Hacker News new | past | comments | ask | show | jobs | submit login
Go Browser Package (dineshgowda.com)
56 points by dineshgowda24 4 months ago | hide | past | favorite | 27 comments



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.


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.


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”


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


Yeah - maybe "user agent"?


We use the uap-go (https://github.com/ua-parser/uap-go) package which parses the uap-core repo and has support for many more browsers.


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.


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


Good point. I didn't give much attention to this part. I run some benchmarks and move these to compile only once. Thank you.


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.


PageReader? HtmlReader?


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


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.


"browser" seems like a terrible name.

The correct name would be "useragent".


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.


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.


> Almost no-one spoofs their user agent.

Citation needed


Ask one of your non-tech friends to spoof a user agent. And see if they even know what a user agent is.

They won’t.

But also, what exactly were you expecting out of a citation? A survey done about whether people spoof their UA or not? That doesn’t exist and likely never will.


[flagged]


I am well aware what it means. I asked you what you were expecting because it doesn't exist and probably never will. Nobody goes around surveying people about user agents. That just doesn't happen in the real world.


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.


that sounds nice, but history has shown thats never what happens.

what REALLY happens is the most popular browser and even version is determined, and anything thats not that doesn't get tested, and eventually breaks. its the pinnacle of lazy programming. "lets use telemetry so that we can point to data that allows us to make software thats as brittle as possible".


There are limited resources in the world. The bulk of the resources should go to the bulk of the users. It’s a feature that rare configurations are less tested


(Former browser dev)

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


Whoosh


Is this just an ad?



This submission was posted first. You can tell by the id.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: