83182d28a0
fix #132 |
||
---|---|---|
make | ||
src | ||
test | ||
.editorconfig | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
bower.json | ||
LICENSE | ||
Makefile | ||
package.json | ||
README.md | ||
typings.d.ts |
Bowser
A Browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.
So... it works like this:
if (bowser.msie && bowser.version <= 6) {
alert('Hello China');
}
1.1.0 breaking changes
We don't save built script in the repo anymore. The main file (src/bowser.js
) is available through NPM or Bower.
Also you can download minified file from the release page.
1.0.0 breaking changes
browser = require('bowser').browser;
becomes browser = require('bowser');
Bowser Flags
Your mileage may vary, but these flags should be set. See Contributing below.
alert('Hello ' + bowser.name + ' ' + bowser.version);
All detected browsers
These flags are set for all detected browsers:
name
- A human readable name for this browser. E.g. 'Chrome', ''version
- Version number for the browser. E.g. '32.0'
For unknown browsers, Bowser makes a best guess from the UA string. So, these may not be set.
Rendering engine flags
If detected, one of these flags may be set to true:
webkit
- Chrome, Android, iOs, BB, etc.gecko
- Firefox, etc.msie
- IE <= 11msedge
- IE > 11
Safari, Chrome and some other minor browsers will report that they have webkit
engines.
Firefox and Seamonkey will report that they have gecko
engines.
if (bowser.webkit) {
// do stuff with safari & chrome & opera & android & blackberry & webos & silk
}
Device flags
If detected, one of these flags may be set to true:
mobile
- All detected mobile OSes are additionally flaggedmobile
, unless it's a tablettablet
- If a tablet device is detected, the flagtablet
is set instead ofmobile
.
Browser flags
If detected, one of these flags may be set to true. The rendering engine flag is shown in []'s:
chrome
- [webkit
]firefox
- [gecko
]msie
msedge
safari
- [webkit
]android
- native browser - [webkit
]ios
- native browser - [webkit
]opera
- [webkit
if >12]phantom
- [webkit
]blackberry
- native browser - [webkit
]webos
- native browser - [webkit
]silk
- Amazon Kindle browser - [webkit
]bada
- [webkit
]tizen
- [webkit
]seamonkey
- [gecko
]sailfish
- [gecko
]ucbrowser
— [webkit
]qupzilla
— [webkit
]vivaldi
— [webkit
]
For all detected browsers the browser version is set in the version
field.
OS Flags
If detected, one of these flags may be set to true:
mac
windows
- other than Windows Phonewindowsphone
linux
- other thanandroid
,chromeos
,webos
,tizen
, andsailfish
chromeos
android
ios
- also sets one ofiphone
/ipad
/ipod
blackberry
firefoxos
webos
- may also settouchpad
bada
tizen
sailfish
osversion
may also be set:
osversion
- for Android, iOS, Windows Phone, WebOS, Bada, and Tizen. If included in UA string.
iOS is always reported as ios
and additionally as iphone
/ipad
/ipod
, whichever one matches best.
If WebOS device is an HP TouchPad the flag touchpad
is additionally set.
Browser capability grading
One of these flags may be set:
a
- This browser has full capabilitiesc
- This browser has degraded capabilities. Serve simpler versionx
- This browser has minimal capabilities and is probably not well detected.
There is no b
. For unknown browsers, none of these flags may be set.
Ender Support
package.json
"dependencies": {
"bowser": "x.x.x"
}
if (require('bowser').chrome) {
alert('Hello Silicon Valley')
}
Contributing
If you'd like to contribute a change to bowser, modify the files in src/
, then run the following (you'll need node + npm installed):
$ npm install
$ make test
Please do not check-in the built files bowser.js
and bowser.min.js
in pull requests.
Adding tests
See the list in src/useragents.js
with example user agents and their expected bowser object.
Whenever you add support for new browsers or notice a bug / mismatch, please update the list and check if all tests are still passing.
License
Licensed as MIT. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.