How to use ua-parser-js - 10 common examples

To help you get started, we’ve selected a few ua-parser-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / ua-parser-js / ua-parser-js-tests.ts View on Github external
parser.getEngine().version

    // OS
    result.os.name
    result.os.version
    parser.getOS().name
    parser.getOS().version

    // CPU
    result.cpu.architecture
    parser.getCPU().architecture

    // Extensions
    var uaString = 'ownbrowser/1.3';
    var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
    var parser = new UAParser(uaString, { browser: ownBrowser });

}
github DefinitelyTyped / DefinitelyTyped / types / ua-parser-js / ua-parser-js-tests.ts View on Github external
function test_parser() {
    var ua = 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6';
    var parser = new UAParser(ua);
    var result = parser.getResult();

    parser.getUA()
    parser.setUA("foo")

    result.ua

    // browser
    result.browser.name
    result.browser.version
    parser.getBrowser().name
    parser.getBrowser().version

    // device
    result.device.model
    result.device.type
github DefinitelyTyped / DefinitelyTyped / ua-parser-js / ua-parser-js-tests.ts View on Github external
parser.getEngine().version

    // OS
    result.os.name
    result.os.version
    parser.getOS().name
    parser.getOS().version

    // CPU
    result.cpu.architecture
    parser.getCPU().architecture

    // Extensions
    var uaString = 'ownbrowser/1.3';
    var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
    var parser = new UAParser(uaString, { browser: ownBrowser });

}
github DefinitelyTyped / DefinitelyTyped / ua-parser-js / ua-parser-js-tests.ts View on Github external
parser.getEngine().name
    parser.getEngine().version

    // OS
    result.os.name
    result.os.version
    parser.getOS().name
    parser.getOS().version

    // CPU
    result.cpu.architecture
    parser.getCPU().architecture

    // Extensions
    var uaString = 'ownbrowser/1.3';
    var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
    var parser = new UAParser(uaString, { browser: ownBrowser });

}
github DefinitelyTyped / DefinitelyTyped / types / ua-parser-js / ua-parser-js-tests.ts View on Github external
parser.getEngine().name
    parser.getEngine().version

    // OS
    result.os.name
    result.os.version
    parser.getOS().name
    parser.getOS().version

    // CPU
    result.cpu.architecture
    parser.getCPU().architecture

    // Extensions
    var uaString = 'ownbrowser/1.3';
    var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
    var parser = new UAParser(uaString, { browser: ownBrowser });

}
github luan007 / edge-node-wrt / Apps / Launcher / drivers / P0FService.ts View on Github external
/// 
var UAParser = require('ua-parser-js');
var parser = new UAParser.UAParser();

class P0FService implements IInAppDriver {

    match(dev:IDevice, delta:IDriverDetla, cb:Callback) {
        //console.log("------------\n P0f match Called", dev.bus.data);
        cb(undefined, {});
    }

    attach(dev:IDevice, delta:IDriverDetla, matchResult:any, cb:PCallback) {
        console.log("P0f ATTACH Called");
        cb(undefined, {valid: true});
    }

    change(dev:IDevice, delta:IDriverDetla, cb:PCallback) {
        var runtimekey = 'App_' + global.runtime_id + ':P0F';
        var devAssump = dev.assumptions[runtimekey];
github vpdb / server / src / tokens / token.serializer.ts View on Github external
protected _simple(ctx: Context, doc: TokenDocument, opts: SerializerOptions): TokenDocument {
		const token = pick(doc, ['id', 'label', 'type', 'provider', 'is_active', 'last_used_at', 'expires_at', 'created_at']) as TokenDocument;

		token.scopes = doc.scopes;

		// parse name for browser string
		const browser = new UAParser(doc.label).getResult();
		if (browser.browser.name && browser.os.name) {
			token.browser = browser;
		}
		return token;
	}
github Venryx / DebateMap / Source / Frame / General / UserAgent.ts View on Github external
| "Firefox" // desktop and mobile
	| "Safari" | "Mobile Safari" // desktop and mobile
	// supported, but not promoted (eg, mentioned in browser-not-supported warning)
	| "Chrome WebView" // android-browser
	| "Edge" // desktop and mobile (they're the same);
type BrowserName =
	| "Amaya" | "Android Browser" | "Arora" | "Avant" | "Baidu" | "Blazer" | "Bolt" | "Camino" | "Chimera" | "Chrome"
	| "Chromium" | "Comodo Dragon" | "Conkeror" | "Dillo" | "Dolphin" | "Doris" | "Edge" | "Epiphany" | "Fennec"
	| "Firebird" | "Firefox" | "Flock" | "GoBrowser" | "iCab" | "ICE Browser" | "IceApe" | "IceCat" | "IceDragon"
	| "Iceweasel" | "IE" | "IE Mobile" | "Iron" | "Jasmine" | "K-Meleon" | "Konqueror" | "Kindle" | "Links"
	| "Lunascape" | "Lynx" | "Maemo" | "Maxthon" | "Midori" | "Minimo" | "MIUI Browser" | "Safari" | "Mobile Safari"
	| "Mosaic" | "Mozilla" | "Netfront" | "Netscape" | "NetSurf" | "Nokia" | "OmniWeb" | "Opera" | "Opera Mini" | "Opera Mobi" | "Opera Tablet"
	| "PhantomJS" | "Phoenix" | "Polaris" | "QQBrowser" | "RockMelt" | "Silk" | "Skyfire" | "SeaMonkey" | "SlimBrowser"
	| "Swiftfox" | "Tizen" | "UCBrowser" | "Vivaldi" | "w3m" | "WeChat" | "Yandex";

let parser = new UAParser();
export function GetBrowser(): {name: BrowserName, version: string} {
	return parser.getBrowser();
}
/*export function GetBrowserName(): BrowserName {
	return parser.getBrowser().name;
}
export function GetBrowserVersion(): string {
	return parser.getBrowser().version;
}*/
github Polymer / tools / packages / browser-capabilities / src / browser-capabilities.ts View on Github external
export function browserCapabilities(userAgent: string): Set {
  const ua = new UAParser(userAgent);
  const capabilities = new Set();
  let browserName = ua.getBrowser().name || '';
  if (browserName === 'Chrome' && ua.getOS().name === 'iOS') {
    // Chrome on iOS is really Safari.
    browserName = 'Mobile Safari';
  }
  const predicates = browserPredicates[browserName] || {};
  for (const capability of Object.keys(predicates) as BrowserCapability[]) {
    if (predicates[capability](ua)) {
      capabilities.add(capability);
    }
  }
  return capabilities;
}
github duskload / react-device-detect / src / init.js View on Github external
function init() {
  if (typeof window !== 'undefined') {
    if (window && window.navigator) {
      UA = new UAParser();

      browser = UA.getBrowser();
      cpu = UA.getCPU();
      device = UA.getDevice();
      engine = UA.getEngine();
      os = UA.getOS();
      ua = UA.getUA();
    }
  }
}

ua-parser-js

Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent & Client Hints data. Supports browser & node.js environment

AGPL-3.0
Latest version published 4 days ago

Package Health Score

97 / 100
Full package analysis