$ npm install browserslist-useragent
Find if a given user agent string satisfies a browserslist query.
It automatically reads the browserslist configuration specified in your project,
but you can also specify the same using the options
parameter.
If you wish to target modern browsers, read this.
Note, browserslist
is a peer dependency, so make sure you have that installed in your project.
npm install browserslist-useragent
# or
yarn add browserslist-useragent
const { matchesUA } = require('browserslist-useragent')
matchesUA(userAgentString, options)
// with browserslist config inferred
matchesUA('Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/54.0')
//returns boolean
// with explicit browserslist
matchesUA(
'Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/54.0',
{ browsers: ['Firefox > 53'] }
)
// returns true
Option | Default Value | Description |
---|---|---|
browsers | — | Manually provide a browserslist query (or an array of queries). Specifying this overrides the browserslist configuration specified in your project. |
env | — | When multiple browserslist environments are specified, pick the config belonging to this environment. |
path | process.cwd() |
Specify a folder to search for the browserslist config (if it differs from the current working directory) |
ignorePatch | true |
Ignore differences in patch browser numbers |
ignoreMinor | false |
Ignore differences in minor browser versions |
allowHigherVersions | false |
For all the browsers in the browserslist query, return a match if the user agent version is equal to or higher than the one specified in browserslist. See why this might be useful. |
and_chr
| ChromeAndroid
| Chrome
Samsung
ff
| and_ff
| FirefoxAndroid
| Firefox
ios_saf
| iOS
Safari
ie
| ie_mob
Edge
Electron
PRs to add more browserslist supported browsers are welcome 👋
All browsers on iOS (Chrome, Firefox etc) use Safari's WebKit as the underlying engine, and hence will be resolved to Safari. Since browserslist
is usually used for
transpiling / autoprefixing for browsers, this behaviour is what's intended in most cases, but might surprise you otherwise.
Right now, Chrome for Android and Firefox for Android are resolved to their desktop equivalents. The caniuse
database does not currently store historical data for these browsers separately (except the last version) See #156. However,
safari for iOS and desktop can be matched separately, since this data is available for both.
unreleased versions
to your browserslist query, and set ignoreMinor
and ignorePatch
to true so that alpha / beta / canary versions of browsers are matched.allowHigherVersions
to true
. For all the browsers specified in your browserslist query, this will return a match if the user agent version is equal to or higher than those specified in your browserslist query. Use this with care though, since it's a wildcard, and only lightly tested.© 2010 - cnpmjs.org x YWFE | Home | YWFE