Home & blog  /  Scripts  /  view post  /

BAPS: Browser and plugin sniffer

Overview

Browser and plugin sniffer (BAPS) is a tool to detect factors regarding a user's environment, such as browser, version, language, plugins and more. Browser sniffing is famously fiddley due to a lack of consistent implementation by browser vendors (until recently, even jQuery had given up trying to consolidate this with its $.browser object). This script aims for reliable detection. It sets a global variable, baps, an object through which the various pieces of data can be accessed.

Example

About you:

Here's the code behind that example:

1

    2

    6

Usage

Simply call the script into your page. It will set a global variable, baps, an object which contains the following properties:

browser - the real name of the user's browser (e.g. Chrome - not Netscape!)

browserVer - the version of the user's browser. See notes.

language - the user's language. See notes.

cookiesEnabled - whether or not the user has cookies enabled

platform - a string pertaining to the user's OS, e.g. 'MacIntel' or 'WinNT 5.1'. See notes.

...and then some more info regarding the major plugins, if installed:

flash - the version of Flash Player plugin installed

wmp - the version (IE) or presence (non-IE) of the Windows Media Player plugin installed. See notes.

quickTime - the version of the QuickTime plugin installed

BAPS can easily be extended to sniff for more plugins. Check out this very helpful page for how to do this for the most common plugins.

Notes

The inconsistent, murky world of browser sniffing therefore guarantees quite a few caveats...

Browser version

Sometimes browsers expose two versions to JS - the release version and the build version. For example, Opera 11.52 actually tells navigator.appVersion that it's 9.8, becuase that's the version of the build that 11.52 is bundled from. Since, as a developer, you will nearly always want to know the 11.52 and not 9.8 (11.52 is exposed to navigator.userAgent, by the way), BAPs uses the latter for browserVer.

Language

One of the greatest inconsistencies in how browser vendors approach the navigator object is to do with language. Browsers variously define language, userLanguage, userLanguage and sysLanguage. Where supported, language is used (but Opera, for example, also supports userLanguage).

Platform

The navigator.platform property is not overly useful as it doesn't normally give you the name of the OS release - only its build. Windows XP, for example, comes up as 'NT 5', whereas Mac Snow Leopard is simply MacIntel.

wmp

With plugin detection, it's a case of IE vs. the rest. IE exposes info about installed plugins not through navigator.plugins but through MS proprietary ActiveX. One issue with this is you cannot detect WMP version except in IE - only whether it is installed or not.

post new comment

Comments (1)

Samson, at 14/11/'11 14:13, said:
Very handy indeed. It makes $.browser and other browser/platform detection techniques look very inadequate.