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
npm i browser-version-detection --save
Script returns object with browser name and version, for example:
const output = {
name: "Chrome",
version: 62,
};
import { detectBrowser } from "browser-version-detection";
detectBrowser(window.navigator);
output
const output = {
name: "Chrome",
version: 64,
};
import { detectBrowserName } from "browser-version-detection";
detectBrowserName(window.navigator.userAgent);
output
const output = "Chrome";
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
pnpm i
pnpm start
pnpm test