browser-detection

Detect browser

Build Status Test Coverage codecov

Browser detection using the user agent. Tested on most popular browser in the World on October 2017 (and updated on July 2023), statistic gets from StatCounter.

It’s worth re-iterating: it’s very rarely a good idea to use user agent sniffing. You can almost always find a better, more broadly compatible way to solve your problem!

More details here

Documentation

Installation

npm i browser-version-detection --save

Script returns object with browser name and version, for example:

const output = {
  name: "Chrome",
  version: 62,
};

API

Get browser name and version

import { detectBrowser } from "browser-version-detection";

detectBrowser(window.navigator);

output

const output = {
  name: "Chrome",
  version: 64,
};

Get browser name

import { detectBrowserName } from "browser-version-detection";

detectBrowserName(window.navigator.userAgent);

output

const output = "Chrome";

Get browser version

import {
  detectBrowserName,
  detectBrowserVersion,
} from "browser-version-detection";

const name = detectBrowserName(window.navigator.userAgent);
detectBrowserVersion(window.navigator, name);

output

const output = 64;

Minified script located in dist/ folder

Contribution

pnpm i
pnpm start

Test

pnpm test