bowser-jr
v1.0.6
Published
Light-weight, composable browser detector
Downloads
733
Readme
Bowser Jr.
A small, lightweight and composable browser detection utility heavily inspired by bowser
.
Installation
Install it using your favourite package manager:
$ npm install bowser-jr
# or
$ yarn add bowser-jr
# or
$ pnpm add bowser-jr
Usage
Now just import getParser
and the parsers
you need:
import { getParser } from 'bowser-jr';
import { getBrowserName, browserParser } from 'bowser-jr/browser';
const parser = getParser(window.navigator.userAgent, { use: [browserParser] });
console.log(getBrowserName(parser)); // outputs `Firefox`
Using multiple parsers
You can use multiple parsers to extract more information from the user agent:
import { getParser } from 'bowser-jr';
import { browserParser } from 'bowser-jr/browser';
import { engineParser } from 'bowser-jr/engine';
import { osParser } from 'bowser-jr/os';
import { platformParser } from 'bowser-jr/platform';
const parser = getParser(window.navigator.userAgent, {
use: [browserParser, engineParser, osParser, platformParser],
});
console.log(parser.getResult());
Bowser compat utilities
bowser-jr
also comes with a compatibility utility for bowser
to make adoption a little easier:
import BowserCompat from 'bowser-jr/compat';
const browser = BowserCompat.getParser(window.navigator.userAgent);
console.log(browser.getBrowser());
// outputs
{
name: "Internet Explorer"
version: "11.0"
}