Category Archives: user agent

Weirdest User Agent String (Updated)

>Investigating a reported bug with one of our PensioenPage websites (IE 8 being detected as IE6) I found out the cause of the issue: An IE8 instance returning the following user agent string:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SIMBAR={B81922DF-CABA-4976-8A80-B27BE01CAC7C}; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Creative ZENcast v2.01.01)

Note that there’s both MSIE 8.0 and MSIE 6.0 in the string! This is the weirdest user agent string I’ve ever seen.

Update (August 25, 2009): And I’m not the only one seeing this kind of agent strings, I just noticed a FancyBox mailing list posting with a similar one:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; InfoPath.2)

And if you search for “Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0;” on Google, you can find a lot of similar ones. It’s a strange world.


Combining CSS and User Agent Sniffing

>Avoid sniffing if you can
User agent sniffing is bad and that’s known. So avoid it if you can.

However, in some cases a browser is just acting weird and you cannot ignore that, it needs some specific CSS instructions. Internet Explorer 6 and 7 are prime examples here.

The old days: CSS hacks
In the past, this was resolved with odd CSS filters (better known as hacks), constructs that were known to work in some browsers and be ignored in some other browsers. To do this well, you need to know about the quirks of all browsers. This is not scalable, with new browsers coming out all the time.

Alternative: Sniffing and CSS classes
Here’s an alternative: Use server-side agent sniffing and put the results in a class attribute in the HTML. This allows you to write CSS rules like:

.Browser-Opera ul.ModList li {display:block}

or even:

.BrowserOS-MacOS-10.Browser-Firefox-3-5 li.FooBar {margin-left:2px}

To see this in action, have a look at the source code of the PensioenPage site:

or, with indentation enabled in the source code:

Note that the user agent sniffing we implemented has more than 160 unit tests, detecting (Mobile) Internet Explorer, Opera Desktop/Mobile/Mini, Firefox, the old Netscape browsers, Chrome, Safari, Maxthon, etc.

Operating systems detected include Mac OS X, various Windows versions, BSD variants, Solaris, Linux, the iPhone OS, etc.

Finally, the browser engine is also detected, allowing rules like this one:

.BrowserEngine-Trident div.Tip {padding:0}