Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Anyone doing anything with user agents should use ua-parser[0]. Don't even bother trying to do any of this yourself.

If ua-parser doesn't exist in your language, just pull the yaml file out of ua-core. That defines the regexes you should use and how they translate to browser versions (and os versions and devices).

[0] https://github.com/ua-parser



Shameless plug for the WhatIsMyBrowser.com API:

https://developers.whatismybrowser.com/api/

As per modern web dev standards: you should always use feature detection not agent sniffing to handle cross browser issues; however having accurate user agent detection is really handy for trouble shooting customer issues, bot detection, spotting trends etc.


Are you encouraging people to do browser sniffing accurately? Aren’t we supposed to discourage such sniffing instead?


Ideally, you would not care at all. You would simply develop HTML 4/5/6 a user has a browser that supports that spec.

In reality, browsers have known bugs that last for years, you need to collect stats to figure out support policies, and you need to reproduce customer bugs.

Example: old versions of Firefox have an RCE vulnerability if you use third party jsonp apis. If you use these apis but don't block these ff versions, your users will be vulnerable.


Exactly. I had to deal with this due to Chrome 45 blocking flash[0]. While that might not seem like something worth targeting specific browsers, Chrome's implementation of blocking flash was an advertiser's worst nightmare. In order to render the page properly, the page would load with flash enabled on all content. It would then pause the flash runtime on all content not deemed "important". This had the wonderful effect of giving a video ad enough time to start playing a few frames and to fire the impression that results in the advertiser getting billed for showing the ad. This would be flat out fraud on our part (a major video ad exchange), so we had to aggressively avoid allowing flash ads to buy spots from chrome 45 and later.

We used ua-parser and everything went very smoothly.

[0] https://www.infoq.com/news/2015/08/chrome-45-flash


You can still want to parse UAs for other reasons. I used such a library recently in a project where a user is shown their login history, including what OS and browser was used, in a human-readable format (e.g. "Firefox 58 on Linux").




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: