NedStarkOfWinterfell
NedStarkOfWinterfell

Reputation: 5243

Safe feature-based browser detection

I have been doing a bit of research on safe and reliable browser detection. Given the fact that parsing navigator.userAgent is the worst way to do so, since it can be easily spoofed by a user, th best bet seems to be using feature-detection. So, based on various articles in StackOveflow and elsewhere, this is what it looks like finally:

IE: /*@cc_on!@*/false
Firefox: -moz-box-sizing
Safari: window.getComputedStyle && !window.globalStorage && !window.opera
Opera: window.opera && window.opera.version
Chrome: window.chrome

Given that these will be maintained and monitored for future release of browsers (when one might disable a feature we are now using to detect it, or may be some other browser may implement it, thus the test will return true for that browser also), are there any caveats in this methods? Can the user, in any way, do stuff so that even these will return wrong results?

Upvotes: 0

Views: 232

Answers (1)

Knu
Knu

Reputation: 15144

are there any caveats in these methods? Can the user, in any way, do stuff so that even these will return wrong results?

AFAIK you have to take into account two things. First an ID, depending on the browser, could pollute the global scope. Secondly you can't, already, trust the prefixes to be browser specific anymore. I would recommend, as others users pointed out in comments, to rely on feature detection instead (what you are doing is correlated inference).

As a side note, your Safari filter is not reliable.

Upvotes: 1

Related Questions