Firefox goes 2-digit, time to check your UA sniffing scripts

We all know it: UA-based browser detection is bad, the right way is feature-detection. Regardless, legacy code relies upon UA sniffing and may need to be updated for Firefox 10′s release.

Even if it looks simple, UA parsing has proven to be a headache for numerous script authors. Though the structure of an UA is defined in the HTTP specification, the way relevant information is conveyed varies from one vendor to another. Also, the information you want to extract from it is not always the same: sometimes you want to know the browser (Firefox, SeaMonkey, Safari, Chrome, IE, Opera…), but most of the time you want to know the engine that powers them (Gecko, Webkit, Trident,…). You also need to get the version of the browser or the engine.

Old scripts often made some undue assumptions. Some are assuming that browser version numbers will never reach 10… This is not the case: Opera and Chrome have already crossed this landmark long ago, Firefox will reach it next week and IE soon after.

A few examples of Firefox UAs that your scripts should allow:

  • Regular Firefox version: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/10.0
  • Nightly and Aurora Firefox versions: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0a1) Gecko/20120122 Firefox/12.0a1
  • Chemspill Firefox version (three numbers) Mozilla/5.0 (Windows NT 6.2; rv:10.0.1) Gecko/20100101 Firefox/10.0.1

So, it is the last moment to check your UA-based browser detection code before your site goes havoc!

Last chance to check

Do it right now, in two weeks it would be too late.

What to do?

  1. Code inspection: check your code to see if there is some UA-based browser detection code. If so, check if it handles multi-digit versions. (At the same time you could check if it is useful at all. Some old UA-detection code has not worked in ages, or try to go around problems fixed since years in browser…)
  2. Library inspection: lots of libraries perform UA-based browser detection. If you are using any of them, check if it still is working with a version of Firefox with 2 digits. If not, notify the author of the lib and open a bug on bugzilla so that we can help others as all their customers are likely to suffer from the same problem.
  3. Check if your site is working with the next Firefox version: download the Beta release of Firefox 10 (you can run several versions of Firefox simultaneously) It is always a good idea to use the beta, or even the aurora, version of Firefox if you are maintaining a site: you’ll discover incompatibilities earlier and will get time to fix them before your users start complaining. We are doing our best to prevent problems, but sometimes old code rely on incorrect behavior and stop working even when we are only fixing bugs.
  4. Test other sites :-). Use the beta or aurora version of Firefox and surf the web. When you hit a UA-related problem report it with bugzilla. Give us as much info as possible like the importance of the site in your country and if you have conducted any action yourself. That way our evangelism team will be able to prioritize work adequately.

Finally, you should plan to get rid of these UA-based browser detection mechanism. If you can’t — and I know it isn’t always possible — I would be glad to know why: so please let us know in the comments below.

Now it is time to check your sites 🙂

Thank you very much for your help.

View full post on Mozilla Hacks – the Web developer blog

7 thoughts on “Firefox goes 2-digit, time to check your UA sniffing scripts

  1. Tai Travis

    The Modernizer js library is a great solution to this problem. You can configure a custom download so you only need to test for the features you need.

  2. Mogden

    UA version sniffing is indispensable when working around browser bugs. For example, Chrome Windows < 18 has horrible problems playing lots of HTML5 audio. It'll crash at some unpredictable time. How could we detect that, in order to reduce the use of sounds in our app, in a nice way?

  3. Aryeh Gregor

    Here’s a case where MediaWiki UA-sniffs for Gecko:

    http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/wikibits.js?revision=108550&view=markup#l495

    The comment explains it pretty well. In theory it should be possible to test for it by creating an iframe and sticking it in the page and navigating it to a fragment before it’s finished loading and seeing if it jumps, but realistically, it’s not practical. So UA sniffing is used instead.

  4. Mathias Bynens

    It would probably be useful to include an example double-digit UA string in this blog post.

  5. David Mulder

    I remember using some browser detection + os detection to style certain input elements consequently (one of which was the file upload field). Secondly I also used it to account for a 1px difference in font-size on different browsers (not sure about the details anymore, so I don’t know whether that was a browser issue or a (google web)font issue). Either way, both issues that couldn’t be detected directly. Oh and, I also used this kind of detection to block a mobile web-app from non-mobile devices.

Leave a Reply