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
- npm
- yarn
- bun
pnpm add get-browser
npm install get-browser
yarn add get-browser
bun 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:
- unpkg
- jsDelivr
- ESM (import maps)
<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>
<script src="https://cdn.jsdelivr.net/npm/get-browser/dist/umd/get-browser.global.js"></script>
<script>
console.log(GetBrowser.detect());
</script>
<script type="importmap">
{ "imports": { "get-browser": "https://esm.sh/get-browser" } }
</script>
<script type="module">
import { detect } from 'get-browser';
console.log(detect());
</script>
Import style
Both ESM and CJS work — the exports map resolves types correctly for each:
- ESM
- CommonJS
- UMD global
import { detect, isMobile, browsers, type Browser } from 'get-browser';
const b: Browser = detect();
const { detect, isMobile, browsers } = require('get-browser');
/** @type {import('get-browser').Browser} */
const b = detect();
<script src="https://unpkg.com/get-browser/dist/umd/get-browser.global.js"></script>
<script>
const b = GetBrowser.detect();
</script>
Requirements
| Minimum | |
|---|---|
| Node.js | >= 20 (active LTS — 20, 22, 24) |
| TypeScript | >= 5.0 (lower may have issues with verbatimModuleSyntax) |
| Browsers | Evergreen — 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.
Continue with the Quickstart for the 10-line tour, or jump straight into the Playground to see every predicate in action.