blogger.com’s browser detection unconvincing

Detecting browsers by name is a widespread JavaScript practice which is frowned upon for good reasons: you can't possibly cover all browsers, it requires update every time a new browser emerges and it is much easier to detect capabilities with so-called object detection.

Blogger has some fairly advanced interface features and obviously need detection. Here is their script:

<http://www.blogger.com/app/scripts/detect.js>

It is an odd and not quite convincing bastard between browser detection and object detection: it tries to detect browsers by checking what objects are supported.

The reason why this fails is that they do not actually detect the objects the scripts rely on. For instance, here is their Mozilla/FireFox detection:

//Gecko, actually Mozilla 1.2+

this.MOZILLA = function()

{

try {

return this.Run(

document.implementation

&& document.implementation.createDocument

&& !document.contains

)!=false;

} catch(e) {return false;}

}

The DOM items they check for are all supported in Opera, so the script will think Opera is Mozilla. (It will also think Opera is IE, and behave quite randomly depending on what order the script looks for browsers in!)

Then, over in <http://www.blogger.com/app/scripts/form.textbar.js> they say:

if (Detect.MOZILLA()) {

HTMLElement.prototype.click = function

Now, the HTMLElement object in fact is only supported by Mozilla. Their script depends on an object that they do not test for because in the author's mind it is still about "browser detection" rather than "capability detection". When they make such assumptions anyway, they might as well detect browsers by name..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s