Edit 9/9/2010: This information has been superseded by an updated post here. Please refer there for final information on the changes for Firefox 4.
With a title like that, you just know this is going to be fun. (No, seriously.)
The user agent string is one of those wonderfully eclectic things, a balance of modernity and antiquity. Except mostly skewed toward antiquity. It’s grown, piece by piece, over the years; because everyone has their own special way of parsing it, it’s a notoriously sensitive beast. Adding to it is relatively simple, but removing or rearranging bits is not.
If you’re a web developer and you rely on bits in the UA string, this post is definitely for you. As it so happens, the UA string for Internet Explorer 9 has undergone some revision, and Microsoft has recently announced the string for IE Mobile. This makes the time ripe for a revision so that web developers can make the necessary changes to sniffer code all at once.
Here are the changes we’ve made so far for Firefox 4, on the Big Three platforms (for a complete reference, see https://developer.mozilla.org/En/Firefox_User_Agent_String_Reference):
Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/yyyymmdd Firefox/4.0.1
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/yyyymmdd Firefox/4.0.1
Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/yyyymmdd Firefox/4.0.1
What’s changed, you say? Here’s what:
1) The "Windows; " prefix is gone from the (surprise!) Windows-specific string.
2) The locale (e.g. "en-US; ") is gone. The locale of the browser is not always the same as the locale the user prefers to view content in — the HTTP Accept header is the recommended source of this information.
3) The "U; " is gone. Back in the day, this was used to denote browsers with strong encryption from those without. Nowadays, no browser ships with weak encryption. This means that if you’re sniffing for "U; ", you should stop doing so, or sniff for the lack of weak encryption ("I; " or "N; ").
4) Testing builds of Firefox (Minefield nightlies and prerelease builds) will now identify themselves as "Firefox/x.y.z", just like release builds.
We may also remove the "Macintosh; " from the Mac UA string, and the way a Linux x86 32-bit browser build running on an x86_64 processor is identified; if we do, you’ll hear about it here.
It’s also worth noting why we didn’t change some things. The "X11" part of the Linux string may appear redundant, but it’s actually not: desktop machines are almost exclusively running X11, but Android phones are not. For reasons like this, the various platform-specific parts of the string are important to know. For instance, there are different tokens for Windows 64 on x64 or IA64, or WoW64 (a 32-bit browser on a 64-bit Windows); PPC or Intel on Mac OS X; and the various environments and architectures for Linux. A list of the common variations can be found at the link above. There’s also a text file here for your testing convenience.
There are some other important changes relating to how the UA string can be modified by external programs, Firefox addons, and users themselves. I’ll detail these changes in an upcoming post, but suffice to say: the days of horrendously long and arcane strings are over.
Now, if you’re a web developer, take note! These changes will be in Firefox 4 Beta 5 (soon to be released), so if you want to be ahead of the game, you’re welcome to test against it. As noted above, for a complete list of UA strings to test against in all their glorious variations, see the link above or the text file. Happy sniffing!