Why Do Browsers Have To Be Such Big Liars
<< August | September | October >>
Friday, 24th September 2010
Why do web browsers have to be such big fat liars? I am currently working on a graphical web statistics package and all I want to do is tell people what browsers their visitors use.
To illustrate this example, feel free to check out the W3 Schools Navigator Sample Page. This uses JavaScript to tell you what browser you are using, but the problem affects all programming languages. If you visit this page, you'll notice that in very few situations does it supply the name and version of your browser. Here are some examples of the complications.
Internet Explorer correctly reports "Microsoft Internet Explorer", but if you are using IE8, the version number is displayed as version 4.0. Similarly, IE9 will tell you it is version 5.0.
Firefox 3.6 displays some histrionics by announcing itself as Netscape 5.0.
Chrome is really very cheeky indeed. It will announce itself as "Netscape" and claim to be version 5.0. This is especially naughty because this essentially makes it look like Firefox 3.6 to the casual user.
And because these browsers represent such a huge market share, it basically means it is quite difficult to know what browsers are being used if you trust the Browser Name and Browser Version that they supply.
So how do we solve this mystery... sadly, there isn't an easy way to do it. In order to get some truth out of these mischievous internet navigators, we need to examine the user agent headers, which look a bit like this:
Internet Explorer
The bit that actually tells you is the section that reads "MSIE 8.0"
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; (R1 1.6); .NET
CLR 1.1.4322; Alexa Toolbar; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET
CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Firefox
The part that matters is the bit that reads "Firefox/3.6.10"
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729)
Chrome
The honest bit appears as "Chrome/0.2.148.27"
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
Awkward
So as you can see, things are somewhat awkward in browser world and the only decent way to decipher all of this mess is to write a bunch of rules around all of these browser details in order to translate them into something useful.
So when analysing browser trends, life is a bit harder than it ought to be, but on the plus side, because browser detection is reasonably tricky, it does prevent people from easily changing functionality based on assumptions about the browser and hopefully means that developers use feature detection rather than "browser assumption" to write their websites.