browserslist-useragent is a utility library designed to determine if a given browser user agent string satisfies a specified browserslist query. The current stable version, 4.0.0, marks a significant rewrite in TypeScript and a switch from the 'useragent' parsing library to 'ua-parser-js', which may introduce subtle differences in how user agents are classified. This library seamlessly integrates with existing browserslist configurations found in project files like `.browserslistrc` or `package.json`, but also provides options for explicitly defining browser queries. It supports a comprehensive range of popular browsers, including Chrome, Firefox, Safari, Edge, and Internet Explorer, offering granular control over version matching through options like ignoring patch or minor versions, or allowing higher versions than specified. While there isn't a fixed release cadence, updates are regularly issued to incorporate bug fixes, add support for new browsers, and improve the underlying parsing logic.
npm install browserslist-useragentVerified import paths — ran on the pinned version, not inferred.
Demonstrates matching a user agent against inferred browserslist config, explicit queries, and utilizing options like `allowHigherVersions`.
Thoroughly test user agent matching logic after upgrading to v4.0.0 to ensure consistent behavior with `ua-parser-js`.
Upgrade your Node.js runtime to version 14 or higher.
Install `browserslist` in your project: `npm install browserslist` or `yarn add browserslist`.
Upgrade to `browserslist-useragent` v4.0.0 or newer to benefit from an actively maintained user agent parsing library (`ua-parser-js`).
Ensure you are using `browserslist-useragent` v3.0.3 or higher if relying on `allowHigherVersions` with Safari browser queries.
Install the `browserslist` package: `npm install browserslist` or `yarn add browserslist`.
For ESM projects, use `import { matchesUA } from 'browserslist-useragent';`. Ensure your project is configured for ESM if you intend to use it.Review the `options` object passed to `matchesUA`. Pay close attention to `browsers` (ensuring it's an array of strings), `ignorePatch`, `ignoreMinor`, and `allowHigherVersions`.