Device Detector JS

3.0.3 · active · verified Sun Apr 19

device-detector-js is a robust JavaScript/TypeScript library designed for precise user agent parsing and device detection. It identifies the browser, operating system, device type (desktop, mobile, tablet, TV, etc.), brand, and model from any user agent string. As a JavaScript port of Matomo's highly regarded `device-detector` library (specifically version 4.2.3), it benefits from an extensive and regularly updated open-source user agent database. The current stable version is 3.0.3, and its release cadence is likely tied to updates from the upstream Matomo project to maintain accuracy and coverage. Key differentiators include its lack of external dependencies, comprehensive TypeScript support, and a rigorous testing suite comprising over 10,000 user agent strings. While it functions in both Node.js and browser environments, the library strongly advises against browser-side usage for performance-critical applications due to its size and processing overhead.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the DeviceDetector and parse a common user agent string, logging the structured client, OS, and device details.

import DeviceDetector from 'device-detector-js';

const deviceDetector = new DeviceDetector();
const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36';
const device = deviceDetector.parse(userAgent);

console.log(JSON.stringify(device, null, 2));

view raw JSON →