Skip to main content

Installation

get-browser is published to npm as get-browser. It ships dual ESM + CJS through the exports map, plus a UMD/IIFE bundle for <script> tags. Pick your weapon:

pnpm add get-browser

That's it. No peer dependencies, no postinstall scripts, nothing to configure.

<script> tag (UMD / IIFE)

A minified bundle that exposes the GetBrowser global is published alongside the package. Drop it in a static page without a build step:

<script src="https://unpkg.com/get-browser/dist/umd/get-browser.global.js"></script>
<script>
console.log(GetBrowser.detect());
if (GetBrowser.isMobile()) {
document.body.classList.add('is-mobile');
}
</script>

Import style

Both ESM and CJS work — the exports map resolves types correctly for each:

import { detect, isMobile, browsers, type Browser } from 'get-browser';

const b: Browser = detect();

Requirements

Minimum
Node.js>= 20 (active LTS — 20, 22, 24)
TypeScript>= 5.0 (lower may have issues with verbatimModuleSyntax)
BrowsersEvergreen — last 2 versions of Chrome, Edge, Firefox, Safari. UMD bundle is compiled to ES2018.

Module resolution

The package exposes the modern exports map:

{
"exports": {
".": {
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
}
}
}

"sideEffects": false is set, so unused detectors are dropped during tree-shaking — importing only isChrome ships ~400 bytes.

Verifying the install

pnpm exec tsc --noEmit -e 'import { detect, browsers } from "get-browser"; const b = detect(); b === browsers.CHROME;'

If that compiles, you’re good to go.

Next step

Continue with the Quickstart for the 10-line tour, or jump straight into the Playground to see every predicate in action.