Skip to content

Latest commit

 

History

219 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

detector-js

v2.0.11

Description

DetectorJS, zero-dependency platform/environment detector written in ES6

Please feel free to ask for modifications, fixes or do a PR to improve Detector behavior or add detection rules

Author

Emiliano 'Pixu' Pisu pisuemiliano.1980@gmail.com

Badges

NPM downloads/month GitHub stars GitHub forks GitHub issues GitHub license

Installation

This is a Node.js module available through the npm registry.

It can be installed using either npm or yarn package managers.

npm i detector-js
yarn add detector-js

Usage

Browser (script tag)

<!-- local build -->
<script src="dist/detector.browser.min.js"></script>
<!-- …or a pinned CDN copy (jsDelivr / unpkg) -->
<script src="https://cdn.jsdelivr.net/npm/detector-js@2.0.11/detector.browser.min.js"></script>
<script>
  const detector = new Detector();          // global class, no wrapper needed
  console.log(detector.toFlags());          // { browser, engine, os, cpu, gpu, feature, platform }
  detector.upgrade().then(render);          // optional: real OS via Client Hints (macOS 'Tahoe'…)
</script>

No build step, no bundler, no wrapper: dist/detector.browser.min.js (and the ES2015 build dist/detector.browser.es2015.min.js for legacy webviews) expose a Detector global that reads navigator.userAgent directly. For SRI-pinned CDN snippets run pnpm sri (integrity hashes change per version).

npm (ESM / CJS)

npm i detector-js
import { Detector } from 'detector-js';      // ESM
const { Detector } = require('detector-js'); // CJS

TypeScript

Types ship with the package (index.d.ts + per-package .d.ts).

Privacy

100% client-side - zero network calls, zero storage, zero telemetry. DetectorJS never registers or sends anything anywhere; the data stays in the hands of whoever executes the library. Read the full legal walkthrough (GDPR, ePrivacy, D.Lgs. 196/2003, CCPA, papers) in PRIVACY.md.

Documentation

Check out the Latest Documentation

Governance & community

CONTRIBUTING.md · CODE_OF_CONDUCT.md · SECURITY.md · GOVERNANCE.md

Monorepo structure

detector-js v3 is a zero-dependency vanillaJS monorepo:

packages/
  core/       @detector-js/core       asserts, FlagsClass, CssFlagsClass, polyfills
  feature/    @detector-js/feature    Feature, AudioFeature, VideoFeature (+ modern WebAPIs)
  software/   @detector-js/software   Browser, Engine, OS
  hardware/   @detector-js/hardware   Platform, Device, CPU, GPU
  detector/   @detector-js/detector   Detector (composes everything)

Runtime dependencies are limited to the internal workspaces: zero external dependencies.

The scoped packages can be consumed individually:

import { Browser } from '@detector-js/software';
import { Detector } from '@detector-js/detector';

Full example output

import Detector from 'detector-js';

const detector = new Detector('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.3 Safari/605.1.15');

console.log(detector);
// {
//   engine:{
//     name:'WebKit',
//     version:'605.1.15'
//   },
//   browser:{
//     name:'Safari',
//     version:'12.0.3'
//   },
//   os:{
//     name:'macOS',
//     version:'10.14.3',
//     versionName:'Mojave'
//   },
//   cpu:{
//     platform:'MacIntel',
//     cores:1,
//     architecture:'x64',
//     vendor:'intel'
//   },
//   gpu:{
//     webGLVendor:'WebKit',
//     webGLRenderer:'WebKit WebGL',
//     vendor:'Intel Inc.',
//     model:'Intel Iris',
//     renderer:'Intel Iris OpenGL Engine'
//   },
//   platform:'desktop',
//     feature: {
//     pointerEnabled:false,
//     pixelRatio:1,
//     pointerLock:true,
//     quirksMode:false,
//     css3D:true,
//     cssTransform:true,
//     cssTransition:true,
//     deviceMotion:false,
//     deviceOrientation:false,
//     contextMenu:false,
//     classList:false,
//     placeholder:true,
//     viewportUnit:true,
//     remUnit:true,
//     canvas:true,
//     svg:true,
//     webGL:true,
//     webGL2:true,
//     webGPU:false,
//     webVR:false,
//     deviceMemory:8,
//     touchPoints:5,
//     touch:false,
//     forceTouch:true,
//     srcset:true,
//     sizes:true,
//     pictureElement:true,
//     dialogElement:false,
//     addEventListener:true,
//     asyncScript:true,
//     battery:false,
//     bluetooth:false,
//     broadcastChannel:false,
//     caches:false,
//     clipboard:false,
//     cors:true,
//     credentials:false,
//     deferScript:true,
//     fetch:true,
//     file:true,
//     fileSystem:false,
//     fullscreen:true,
//     fullscreenKeyboard:true,
//     gamepad:true,
//     geolocation:true,
//     historyAPI:true,
//     indexedDB:true,
//     intersectionObserver:true,
//     littleEndian:false,
//     localStorage:true,
//     matchMedia:true,
//     mediaCapabilities:true,
//     mediaRecorder:false,
//     mediaSession:false,
//     nfc:false,
//     notifications:false,
//     offscreenCanvas:false,
//     online:true,
//     paymentRequest:false,
//     permissions:true,
//     querySelector:true,
//     querySelectorAll:true,
//     resizeObserver:true,
//     serial:false,
//     serviceWorker:true,
//     speechSynthesis:false,
//     storage:true,
//     structuredClone:true,
//     typedArray:true,
//     usb:false,
//     userMedia:false,
//     vibration:false,
//     visualViewport:true,
//     wakeLock:true,
//     webAssembly:true,
//     webAuthn:false,
//     webCrypto:true,
//     webLocks:true,
//     webRTC:false,
//     webShare:true,
//     webSocket:true,
//     webXr:false,
//     worker:true,
//     audio:{
//       supported:true,
//       context:true,
//       formats:{
//         mp3:true,
//         webm:false,
//         ogg:false,
//         opus:false,
//         wav:true,
//         m4a:true
//       }
//     },
//     video:{
//       supported:true,
//       formats:{
//         mp4:true,
//         ogv:false,
//         webm:false
//       }
//     }
//   }
// }

Todo

  • refine browsers regexes
  • refine documentation
  • implement modular custom build feature
  • decide to implement or not device infos detection

Dependencies

None

Dev Dependencies

None

Tests

npm install
npm test

License

MIT

Powered By

JS.ORG Logo