Skip to content
🔍 Library to detect browser, os and device based on the UserAgent String
Branch: master
Clone or download
Latest commit 1992d57 Feb 25, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Fix duplicate script tag + Fix New Opera detection + Update README Oct 26, 2015
builds/1.0.0 2.0 Overhaul WIP Dec 5, 2012
tests Preparing for tests Oct 24, 2015
.gitignore Win10 + MS Edge Update Aug 25, 2015
.travis.yml Update Feb 25, 2019
detect.js Fix duplicate script tag + Fix New Opera detection + Update README Oct 26, 2015
package.json Update deps Feb 25, 2019
regexes.js new files Nov 6, 2018


Note: Detect.js is a JavaScript library to detect platforms, versions, manufacturers and types based on the navigator.userAgent string. This code is based on, and modified from, the original work of Tobie Langel's UA-Parser: UA-Parser is subsequently a port of BrowserScope's user agent string parser.

As initially touted, the biggest contribution to this code is the work of Steve Souders and the list of regex tests.


  • User-Agent parsing (obviously)
  • AMD/Common.js support
  • device, os and browser detection of:
    • name
    • family
    • version
    • major
    • minor
    • patch
    • device supports: manufacturer and type as well
  • Custom regex builds using node.js

Creating a Custom Build

Creating a custom build of the regex profiles will help reduce file size and is strongly recommended. The default detect.js and detect.min.js files include all regex profiles and is therefor much larger then, I'm sure, your needs.

  1. Install Node.js:
  2. Edit build/config.js with you're preferred oss, devices and browsers
  3. Run node build/build.js --input=build/detect.js --output=build/detect.custom.js
  4. The build script should create a custom version of Detect.js at build/detect.custom.js

Example Use

Plain JS:

<script src="detect.js"></script>
iPhone 4 Example User Agent:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7

var ua = detect.parse(navigator.userAgent); // "Mobile Safari" // "Mobile Safari 4.0.5"
ua.browser.version // "4.0.5"
ua.browser.major // 4
ua.browser.minor // 0
ua.browser.patch // 5 // "iPhone" // "iPhone"
ua.device.version // ""
ua.device.major // null
ua.device.minor // null
ua.device.patch // null
ua.device.type // "Mobile"
ua.device.manufacturer // "Apple" // "iOS" // "iOS 4"
ua.os.version // "4"
ua.os.major // 4
ua.os.minor // 0
ua.os.patch // null


var detect = require('detect');
var ua = detect.parse(navigator.userAgent);


  • Install development dependencies using npm install.
  • Install the pre-commit hook by running hooks/
  • Kick off the default build (which will generate detect.js and detect.min.js) with npm start.


Thanks to Adriano Caheté and Julian


  • Some data contained in build/regexes.js is Copyright 2009 Google Inc. and available under the Apache License, Version 2.0.
  • All other code is licensed under a Dual MIT and GPL licence
You can’t perform that action at this time.