Browser sniffing is a common technique tyÃ¥ically used to ensure people accessing your web site will receive the content the most appropriate for their browser. Sometimes it is used willingly to make your site unaccessible. Badly implemented browser sniffing can also lead unaccessibility. No matter how good your back-end is, if your users can’t access the front-end, you won’t get to see any of their money. Except if they are motivated, like me.
I will take today the example of KLM, an otherwise famous company, whose JS code prevents me from accessing their site. I am highly suspicious that this code was deployed today (now yesterday), because I had no problem this morning. I sent them a mail and they told me to call their office. If they had the same price on the web and by phone, I wouldn’t mind. But they don’t.
So what’s the issue? Basically I am redirected to a page that says:

I open my javascript console to see a flury of error messages, including one that points me to this piece of JS code:
function checkBrowser() {
var browser = 'unknown';
browser = getBrowser();
if ((browser == 'WIN_IE6') || (browser == 'WIN_IE55')
|| (browser == 'WIN_IE50') || (browser == 'WIN_MOZ')
|| (browser == 'WIN_FF') || (browser == 'MAC_SAF')
|| (browser == 'MAC_FF') || (browser == 'MAC_MOZ')) {
//browser ok, so to 'normal' site
return;
}
else {
//wrong browser, so to 'browsersupport' page
document.location.href = '/travel/klm_splash/browsersupport.html';
}
}
Yes. Right. I use Firefox 1.5rc3 on Linux (I also sometimes use IE through wine). So is my browser unsupported? Or is it my Operating System?
And what about Opera? I wonder what the users of the cool Nokia 770 Linux tablet will say… Or people browsing the web site from their non Windows based mobile phones…
So as I don’t want to spend time finding new plane tickets elsewhere, I will make it so that I can access their web site.
easy simple solution: the User Agent.
Install an extension to alter your browser User Agent.
I used this:
UA Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051121 Firefox/1.5
And hop! The drawback is that the site doesn’t even know I had issues.
using greasemonkey
GreaseMonkey is a known powerfull extension that allows you to dynamically modify a site thanks to JavaScript. Much more interesting than changing the User Agent right?
Unfortunately I don’t think it is possible to modify the loaded javascript using GreaseMonkey. What one could do instead if enable the user agent dynamically on this site. I didn’t delve into how to achieve that because my laptop just died…
opera and user.js
Opera comes with a pretty powerfull functionality: user.js. It’s even more powerfull than GreaseMonkey.
In particular I could redefine the checkBrowser() function to do nothing:
// ==UserScript==
// @name klm.com - Bypass browser check
// @author Jerome Lacoste
// @namespace http://www.coffeebreaks.org/opera/
// @version 1.0
// @description Bypasses the browser check on klm.com and
// allows access to the site.
// ==/UserScript==
/*
* This script is granted to the Public Domain.
*/
if (window.location.hostname == 'www.klm.com' ){
window.opera.defineMagicFunction(
'checkBrowser',
function (oRealFunction,oThis) {}
);
}
Unfortunately Opera is broken for other reasons on klm.com, and I wasn’t able to test this script. But you get the idea.
messages
Users, when web developers screw up, do not despair. Your imagination (and a good toolbox) may come to the rescue.
KLM, I hope you are happy. Not only did I identify an issue on your site, gave at least one alternative for working around it, and bought a plane ticket.
Still, I would strongly recommend you to set up a better testing procedure before deploying your web application…