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
If you wish to target modern browsers, read this.
npm install browserslist-useragent
const matchesUA =// with browserslist config inferred//returns boolean// with explicit browserslist// returns true
|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.|
||Specify a folder to search for the browserslist config (if it differs from the current working directory)|
||Ignore differences in patch browser numbers|
||Ignore differences in minor browser versions|
||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.|
- Chrome (Chrome / Chromium / Yandex) as
- Samsung Internet as
- Firefox as
- Safari iOS as
- Safari Desktop as
- IE as
- Edge as
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
browserslistis 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
caniusedatabase 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.
When querying for modern browsers
- It is a good idea to update this package often so that browser definitions are upto date.
- It is also a good idea to add
unreleased versionsto your browserslist query, and set
ignorePatchto true so that alpha / beta / canary versions of browsers are matched.
- In case you're unable to keep this package up-to-date, you can set the
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.
## Further reads