top | item 40402734

Go Browser Package

56 points| dineshgowda24 | 1 year ago |browser.dineshgowda.com

27 comments

order

thangngoc89|1 year ago

I couldn’t understand what is the context of Browser until I read the first usage example with the line “Mozilla/5.0…”. I immediately understood that this is a user-agent parsing library.

I would prefer user-agent which is a well understood term.

jjice|1 year ago

I know there's a PHP package of the same name. I wouldn't be surprised if there were other packages of the same name and maybe it's just a namesake that continues.

dlopes7|1 year ago

Just a note, this was a bit difficult to read with the amount of times you repeat the phrase “ browser, device, platform, or bot that was making a request to the application”

dineshgowda24|1 year ago

Yes, it makes sense. Thanks for the input. I have updated the documentation now.

tgv|1 year ago

Not ideal. It is very slow. It takes 8 seconds for 3400 strings. That might be fine for occasional offline usage, but not for frequent usage, and certainly not for use in the backend (although I agree it should not be used there). I guess it matches all regexps against each string.

It also misses some really common user agents, basically all iOS 11 and 12. They may be rare nowadays, but they still occur.

mpcjanssen|1 year ago

It seems to recompile every regex on every matching operation. This is really slow. The compiled regexes should be cached in the different matchers.

silisili|1 year ago

This looks pretty useful, kudos.

If I had any nit to make, it's about browser.NewBrowser. It stutters, and even with just New(), at first I thought it was making a client. Not sure what I'd go with, maybe Parse like net/url?

Again, just a minor nit, not trying to take away what you've done here at all.

kevindamm|1 year ago

PageReader? HtmlReader?

dineshgowda24|1 year ago

Yes, it does right. Honestly, I couldn't find a better name. `Parse` sounds nice, so let me think about it.

kgeist|1 year ago

It lists Sputnik as one of the supported browsers but it's a dead project once developed by the Russian government, and now it seems to be abandoned (last updates in 2021). I'd just delete any mentions of it.

llmblockchain|1 year ago

"browser" seems like a terrible name.

The correct name would be "useragent".

38|1 year ago

please stop doing stuff like this. its trivial to change the user-agent when making a request with a programming language, so any logic surrounding that should be non existent, or as simple as possible.

the user-agent string has an essentially arbitrary format, so its not really a good place to be reading data from, or worse serving a different response based on the value.

tgv|1 year ago

It's a (minor) necessary evil that gives useful information. Almost no-one spoofs their user agent. I use this to pin down problems on the user side. Our users have all kinds of weird devices (e.g. browsing with a PlayStation) and it can be hard to find where things go wrong. There was a case where we lost more users than usual, and it turned out to be something very subtle related to tab switching in Safari. Without the user agent, we would never have found out.

zuck_vs_musk|1 year ago

This is useful.

If you have a website, you want to collect statistical data on which browsers are accessing your website and test for the best experiences on the top browsers.

dblohm7|1 year ago

(Former browser dev)

Agreed. Feature detection is the way, not UA sniffing.