Skip to content

1000tech/detectOS.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DetectOS.js

Frontend-only browser detection for popular operating systems and browsers in JavaScript without dependencies.

This package is intended for browser runtimes only. It relies on browser APIs such as navigator and should not be used in SSR or backend Node.js code.

Install

NPM:

npm i detectos.js

Yarn:

yarn add detectos.js

Bower:

bower i detectos.js

Usage

import DetectOS from 'detectos.js'
const Detect = new DetectOS()

console.log('We know your browser – it\'s ' + Detect.browser + ' ' + Detect.version);
console.log('We know your OS – it\'s ' + Detect.OS);
console.log('We know everything about you.');

If you instantiate the class outside a browser, it throws an explicit browser-only error. For tests, you can pass a browser-like environment object:

const Detect = new DetectOS({
	navigator: {
		userAgent: 'Mozilla/5.0 ... Chrome/122.0.0.0 Safari/537.36',
		appVersion: '5.0',
		vendor: 'Google Inc.',
		platform: 'MacIntel'
	},
	window: {}
})

Notes

  • The library is browser-only and intended for frontend apps.
  • Detection is based on user-agent sniffing, so results depend on what the browser exposes.
  • Modern Edge, Chrome, Firefox, Safari, Opera, Android, iOS, macOS, Windows and Linux are covered.

Demo

Used on MobiDevices

About

A simple definition of the popular OS and browsers on JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors