Skip to main content

detect()

The headline export. Returns one of the browsers values, narrowed to the Browser union.

Signature(options?: DetectOptions) => Browser
Returns'android' | 'chrome' | 'edge' | 'firefox' | 'ie' | 'opera' | 'safari' | 'unknown'
Bundle cost~1.4 kB (full library, min+gz)
SSR safe✅ Pass { userAgent } to pin

Signature

function detect(options?: DetectOptions): Browser;
interface DetectOptions {
readonly userAgent?: string;
readonly vendor?: string;
}

type Browser =
| 'android'
| 'chrome'
| 'edge'
| 'firefox'
| 'ie'
| 'opera'
| 'safari'
| 'unknown';

Behaviour

Detection runs most-specific first to avoid Chromium-family collisions. Order:

  1. Edge (legacy Edge/, Chromium Edg/, mobile EdgA//EdgiOS/)
  2. Opera (Presto Opera/, Chromium OPR/, or window.opera/window.opr)
  3. IE (MSIE 6–10 or Trident/ 11)
  4. Firefox (any platform, including FxiOS/)
  5. Chrome (desktop Chrome/, iOS CriOS/, pure Chromium/)
  6. Safari (Apple vendor + Safari UA, minus other-browser-on-iOS tokens)
  7. Android WebView (last-resort match on Mozilla/5.0 + Android + AppleWebKit minus the above)
  8. 'unknown' — bots, new browsers, empty UA

Examples

import { detect } from 'get-browser';

const browser = detect();
// In Chrome 140 on macOS → 'chrome'
// In Safari 18 on iPhone → 'safari'
// In Node (no navigator) → 'unknown'

Notes

Treats explicit input as authoritative

When you pass { userAgent }, the library does not read globalThis.navigator — this keeps the function pure with respect to its inputs (no surprise contamination from jsdom or Playwright globals).

No version numbers

This library returns the family name only. Use ua-parser-js if you need versions.

'unknown' is not a bug

Bot UAs, brand-new browsers, and empty strings all resolve to 'unknown' — handle it as a safe fallback rather than an error.

See also