Skip to content

Detect the OS, Browser and WebView from UserAgent String.

License

Notifications You must be signed in to change notification settings

st2one/UserAgent.js

 
 

Repository files navigation

UserAgent.js Build Status

npm

Detect the OS, Browser and WebView from UserAgent String.

This module made of WebModule.

Documentation

Browser, NW.js and Electron

<script src="<module-dir>/lib/WebModule.js"></script>
<script src="<module-dir>/lib/UserAgent.js"></script>
<script>

var ua = new UserAgent();

var result = {
    OS:               ua.OS,
    OS_VERSION:       ua.OS_VERSION,
    BROWSER:          ua.BROWSER,
    BROWSER_ENGINE:   ua.BROWSER_ENGINE,
    BROWSER_VERSION:  ua.BROWSER_VERSION,
    USER_AGENT:       ua.USER_AGENT,
    LANGUAGE:         ua.LANGUAGE,
    WEB_VIEW:         ua.WEB_VIEW,
    DEVICE:           ua.DEVICE,
    AOSP:             ua.AOSP,
    // --- shorthand ---
    iOS               ua.iOS,
    Android           ua.Android,
};

console.dir(result);

/*
{
  "OS": "Mac",
  "OS_VERSION": "10.9.5",
  "BROWSER": "Chrome",
  "BROWSER_ENGINE": "Blink",
  "BROWSER_VERSION": "44.0.2403",
  "USER_AGENT": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36",
  "LANGUAGE": "en",
  "WEB_VIEW": false,
  "DEVICE": "",
  "AOSP": false,
  "iOS": false,
  "Android": false,
}
 */
</script>

WebWorkers

importScripts("<module-dir>lib/WebModule.js");
importScripts("<module-dir>lib/UserAgent.js");

Node.js

require("<module-dir>lib/WebModule.js");
require("<module-dir>lib/UserAgent.js");

About

Detect the OS, Browser and WebView from UserAgent String.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.9%
  • HTML 2.1%