Gathering detailed insights and metrics for bowser
Gathering detailed insights and metrics for bowser
Gathering detailed insights and metrics for bowser
Gathering detailed insights and metrics for bowser
npm install bowser
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,511 Stars
948 Commits
487 Forks
105 Watching
16 Branches
96 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-1.9%
2,696,785
Compared to previous day
Last week
3.4%
14,162,589
Compared to previous week
Last month
9.9%
58,588,837
Compared to previous month
Last year
45.1%
585,306,968
Compared to previous year
26
A small, fast and rich-API browser/platform/engine detector for both browser and node.
Don't hesitate to support the project on Github or OpenCollective if you like it ❤️ Also, contributors are always welcome!
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. Check it out on this page: https://bowser-js.github.io/bowser-online/.
Version 2.0 has drastically changed the API. All available methods are on the docs page.
For legacy code, check out the 1.x branch and install it through npm install bowser@1.9.4
.
First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript, ES6, and CommonJS module systems.
1const Bowser = require("bowser"); // CommonJS 2 3import * as Bowser from "bowser"; // TypeScript 4 5import 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.
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:
1const browser = Bowser.getParser(window.navigator.userAgent); 2 3console.log(`The current browser name is "${browser.getBrowserName()}"`); 4// The current browser name is "Internet Explorer"
or
1const browser = Bowser.getParser(window.navigator.userAgent); 2console.log(browser.getBrowser()); 3 4// outputs 5{ 6 name: "Internet Explorer" 7 version: "11.0" 8}
or
1console.log(Bowser.parse(window.navigator.userAgent)); 2 3// outputs 4{ 5 browser: { 6 name: "Internet Explorer" 7 version: "11.0" 8 }, 9 os: { 10 name: "Windows" 11 version: "NT 6.3" 12 versionName: "8.1" 13 }, 14 platform: { 15 type: "desktop" 16 }, 17 engine: { 18 name: "Trident" 19 version: "7.0" 20 } 21}
You could want to filter some particular browsers to provide any special support for them or make any workarounds. It could look like this:
1const browser = Bowser.getParser(window.navigator.userAgent); 2const isValidBrowser = browser.satisfies({ 3 // declare browsers per OS 4 windows: { 5 "internet explorer": ">10", 6 }, 7 macos: { 8 safari: ">10.1" 9 }, 10 11 // per platform (mobile, desktop or tablet) 12 mobile: { 13 safari: '>=9', 14 'android browser': '>3.10' 15 }, 16 17 // or in general 18 chrome: "~20.1.1432", 19 firefox: ">31", 20 opera: ">=22", 21 22 // also supports equality operator 23 chrome: "=20.1.1432", // will match particular build only 24 25 // and loose-equality operator 26 chrome: "~20", // will match any 20.* sub-version 27 chrome: "~20.1" // will match any 20.1.* sub-version (20.1.19 as well as 20.1.12.42-alpha.1) 28});
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.
.satisfies()
By default you are supposed to use the full browser name for .satisfies
.
But, there's a short way to define a browser using short aliases. The full
list of aliases can be found in the file.
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
Licensed as MIT. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 13/25 approved changesets -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
87 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More