Bowser
A browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.
- +Contents
- Overview
- Use cases @@ -59,29 +59,31 @@
- How can I help?
Overview
The library is made to help to detect what browser your user has and gives you a convenient API to filter the users somehow depending on their browsers.
-Please, note that this is an alpha version. Check out the 1.x branch for a stable version.
-Changes of version 2.0
-The upcoming 2.0 version has drastically changed API. All available methods can be found in the docs
folder from now on and on a webpage soon.
Use cases
First of all, require the library. This is a UMD Module, so it will work for AMD, Typescript and CommonJS module systems.
+Changes of version 2.0
+The version 2.0 has drastically changed API. All available methods can be found in the docs
folder from now on and on a webpage soon.
For legacy code, check out the 1.x branch and install it through npm install bowser@1.9.4
.
Use cases
First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript, ES6, and CommonJS module systems.
const Bowser = require("bowser"); // CommonJS
-import * as Bowser from "bowser" // Typescript
By default, the exported version is the ES5 transpiled version, which do not include any polyfills.
+import * as Bowser from "bowser"; // TypeScript + +import Bowser from "bowser"; // ES6 (and TypeScript with --esModuleInterop enabled)By default, the exported version is the ES5 transpiled version, which do not include any polyfills.
In case you don't use your own babel-polyfill
you may need to have pre-built bundle with all needed polyfills.
So, for you it's suitable to require bowser like this: require('bowser/bundled')
.
As the result, you get a ES5 version of bowser with babel-polyfill
bundled together.
You may need to use the source files, so they will be available in the package as well.
Browser props detection
Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to do it with Bowser:
-const browser = bowser.getParser(window.navigator.userAgent);
+const browser = Bowser.getParser(window.navigator.userAgent);
console.log(`The current browser name is "${browser.getBrowserName()}"`);
// The current browser name is "Internet Explorer"
or
const impression = new Impression();
-const browser = bowser.getParser(window.navigator.userAgent);
+const browser = Bowser.getParser(window.navigator.userAgent);
const browserInfo = browser.getBrowser();
impression.brName = browserInfo.name;
impression.brVer = browserInfo.version;
or
-const browser = bowser.getParser(window.navigator.userAgent);
+const browser = Bowser.getParser(window.navigator.userAgent);
impression.userTechData = browser.parse();
console.log(impression.userTechData);
@@ -105,7 +107,7 @@ console.log(impression.userTechData);
}
}
Filtering browsers
You could want to filter some particular browsers to provide any special support for them or make any workarounds.
It could look like this:
-const browser = bowser.getParser(window.navigator.userAgent);
+const browser = Bowser.getParser(window.navigator.userAgent);
const isValidBrowser = browser.satisfies({
// declare browsers per OS
windows: {
@@ -135,12 +137,6 @@ const isValidBrowser = browser.satisfies({
});
Settings for any particular OS or platform has more priority and redefines settings of standalone browsers.
Thus, you can define OS or platform specific rules and they will have more priority in the end.
More of API and possibilities you will find in the docs
folder.
-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 #build
-$ npm test #run tests
-$ npm run lint #check lint rules
Adding tests
See the list in test/acceptance/useragentstrings.yml
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.
Similar Projects
- Kong - A C# port of Bowser.
@@ -159,7 +155,7 @@ check if all tests are still passing.
diff --git a/docs/parser.js.html b/docs/parser.js.html
index 0646f5a..d1c32a3 100644
--- a/docs/parser.js.html
+++ b/docs/parser.js.html
@@ -26,7 +26,7 @@
@@ -315,6 +315,19 @@ class Parser {
return this.parseEngine();
}
+ /**
+ * Get engines's name
+ * @return {String} Engines's name or an empty string
+ *
+ * @public
+ */
+ getEngineName(toLowerCase) {
+ if (toLowerCase) {
+ return String(this.getEngine().name).toLowerCase() || '';
+ }
+ return this.getEngine().name || '';
+ }
+
/**
* Get parsed platform
* @return {{}}
@@ -480,6 +493,10 @@ class Parser {
return this.getPlatformType(true) === String(platformType).toLowerCase();
}
+ isEngine(engineName) {
+ return this.getEngineName(true) === String(engineName).toLowerCase();
+ }
+
/**
* Is anything? Check if the browser is called "anything",
* the OS called "anything" or the platform called "anything"
@@ -515,7 +532,7 @@ export default Parser;
diff --git a/docs/utils.js.html b/docs/utils.js.html
index 0ae24cb..3866655 100644
--- a/docs/utils.js.html
+++ b/docs/utils.js.html
@@ -26,7 +26,7 @@
@@ -247,7 +247,7 @@ module.exports = Utils;
diff --git a/package-lock.json b/package-lock.json
index 7373671..4a11a78 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9182,6 +9182,12 @@
"minimalistic-crypto-utils": "^1.0.0"
}
},
+ "email-addresses": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-3.0.3.tgz",
+ "integrity": "sha512-kUlSC06PVvvjlMRpNIl3kR1NRXLEe86VQ7N0bQeaCZb2g+InShCeHQp/JvyYNTugMnRN2NvJhHlc3q12MWbbpg==",
+ "dev": true
+ },
"emittery": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/emittery/-/emittery-0.4.1.tgz",
@@ -10335,6 +10341,33 @@
}
}
},
+ "filename-reserved-regex": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-1.0.0.tgz",
+ "integrity": "sha1-5hz4BfDeHJhFZ9A4bcXfUO5a9+Q=",
+ "dev": true
+ },
+ "filenamify": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-1.2.1.tgz",
+ "integrity": "sha1-qfL/0RxQO+0wABUCknI3jx8TZaU=",
+ "dev": true,
+ "requires": {
+ "filename-reserved-regex": "^1.0.0",
+ "strip-outer": "^1.0.0",
+ "trim-repeated": "^1.0.0"
+ }
+ },
+ "filenamify-url": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/filenamify-url/-/filenamify-url-1.0.0.tgz",
+ "integrity": "sha1-syvYExnvWGO3MHi+1Q9GpPeXX1A=",
+ "dev": true,
+ "requires": {
+ "filenamify": "^1.0.0",
+ "humanize-url": "^1.0.0"
+ }
+ },
"fill-range": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz",
@@ -10617,6 +10650,17 @@
"readable-stream": "^2.0.0"
}
},
+ "fs-extra": {
+ "version": "7.0.1",
+ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz",
+ "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==",
+ "dev": true,
+ "requires": {
+ "graceful-fs": "^4.1.2",
+ "jsonfile": "^4.0.0",
+ "universalify": "^0.1.0"
+ }
+ },
"fs-readdir-recursive": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz",
@@ -11311,6 +11355,58 @@
"assert-plus": "^1.0.0"
}
},
+ "gh-pages": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-2.0.1.tgz",
+ "integrity": "sha512-uFlk3bukljeiWKQ2XvPfjcSi/ou7IfoDf2p+Fj672saLAr8bnOdFVqI/JSgrSgInKpCg5BksxEwGUl++dbg8Dg==",
+ "dev": true,
+ "requires": {
+ "async": "^2.6.1",
+ "commander": "^2.18.0",
+ "email-addresses": "^3.0.1",
+ "filenamify-url": "^1.0.0",
+ "fs-extra": "^7.0.0",
+ "globby": "^6.1.0",
+ "graceful-fs": "^4.1.11",
+ "rimraf": "^2.6.2"
+ },
+ "dependencies": {
+ "async": {
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz",
+ "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==",
+ "dev": true,
+ "requires": {
+ "lodash": "^4.17.11"
+ }
+ },
+ "commander": {
+ "version": "2.19.0",
+ "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz",
+ "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==",
+ "dev": true
+ },
+ "globby": {
+ "version": "6.1.0",
+ "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz",
+ "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=",
+ "dev": true,
+ "requires": {
+ "array-union": "^1.0.1",
+ "glob": "^7.0.3",
+ "object-assign": "^4.0.1",
+ "pify": "^2.0.0",
+ "pinkie-promise": "^2.0.0"
+ }
+ },
+ "lodash": {
+ "version": "4.17.11",
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
+ "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
+ "dev": true
+ }
+ }
+ },
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
@@ -11684,6 +11780,16 @@
"integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=",
"dev": true
},
+ "humanize-url": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/humanize-url/-/humanize-url-1.0.1.tgz",
+ "integrity": "sha1-9KuZ4NKIF0yk4eUEB8VfuuRk7/8=",
+ "dev": true,
+ "requires": {
+ "normalize-url": "^1.0.0",
+ "strip-url-auth": "^1.0.0"
+ }
+ },
"ieee754": {
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz",
@@ -12347,6 +12453,15 @@
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=",
"dev": true
},
+ "jsonfile": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
+ "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
+ "dev": true,
+ "requires": {
+ "graceful-fs": "^4.1.6"
+ }
+ },
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@@ -13345,6 +13460,18 @@
"remove-trailing-separator": "^1.0.1"
}
},
+ "normalize-url": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-1.9.1.tgz",
+ "integrity": "sha1-LMDWazHqIwNkWENuNiDYWVTGbDw=",
+ "dev": true,
+ "requires": {
+ "object-assign": "^4.0.1",
+ "prepend-http": "^1.0.0",
+ "query-string": "^4.1.0",
+ "sort-keys": "^1.0.0"
+ }
+ },
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
@@ -15246,6 +15373,16 @@
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==",
"dev": true
},
+ "query-string": {
+ "version": "4.3.4",
+ "resolved": "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz",
+ "integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=",
+ "dev": true,
+ "requires": {
+ "object-assign": "^4.1.0",
+ "strict-uri-encode": "^1.0.0"
+ }
+ },
"querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
@@ -16252,6 +16389,15 @@
}
}
},
+ "sort-keys": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
+ "integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=",
+ "dev": true,
+ "requires": {
+ "is-plain-obj": "^1.0.0"
+ }
+ },
"source-list-map": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz",
@@ -16498,6 +16644,12 @@
"integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=",
"dev": true
},
+ "strict-uri-encode": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
+ "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=",
+ "dev": true
+ },
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@@ -16584,6 +16736,21 @@
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
"dev": true
},
+ "strip-outer": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz",
+ "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==",
+ "dev": true,
+ "requires": {
+ "escape-string-regexp": "^1.0.2"
+ }
+ },
+ "strip-url-auth": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/strip-url-auth/-/strip-url-auth-1.0.1.tgz",
+ "integrity": "sha1-IrD6OkE4WzO+PzMVUbu4N/oM164=",
+ "dev": true
+ },
"styled_string": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/styled_string/-/styled_string-0.0.1.tgz",
@@ -17299,6 +17466,15 @@
"integrity": "sha1-n5up2e+odkw4dpi8v+sshI8RrbM=",
"dev": true
},
+ "trim-repeated": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz",
+ "integrity": "sha1-42RqLqTokTEr9+rObPsFOAvAHCE=",
+ "dev": true,
+ "requires": {
+ "escape-string-regexp": "^1.0.2"
+ }
+ },
"trim-right": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
@@ -17494,6 +17670,12 @@
"uid2": "0.0.3"
}
},
+ "universalify": {
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
+ "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
+ "dev": true
+ },
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
diff --git a/package.json b/package.json
index 91d261e..a06e922 100644
--- a/package.json
+++ b/package.json
@@ -42,6 +42,7 @@
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-ava": "^5.1.0",
"eslint-plugin-import": "^2.14.0",
+ "gh-pages": "^2.0.1",
"jsdoc": "^3.5.5",
"nyc": "^13.2.0",
"sinon": "^6.1.5",
@@ -63,6 +64,7 @@
},
"scripts": {
"build": "webpack --config webpack.config.js",
+ "deploy": "jsdoc -c jsdoc.json && gh-pages --dist docs --dest docs",
"prepublishOnly": "npm run build",
"lint": "eslint ./src",
"testem": "testem",