Détail du package

detector

hotoo7.6kMIT2.5.0

The module for detect client-side information.

utility, userAgent, arale, Browser

readme

detector


NPM version spm version Build Status Coverage Status

中文文档

Client information detector, for auto detect user agent, include:

  1. Device.
  2. Operation System (OS).
  3. Browser.
  4. Rendering Engine.

Detected information data structure like:

detector = {
    device: {
        name: "iphone",
        version: -1,
        fullVersion: "-1",
        [iphone]: -1
    },
    os: {
        name: "ios",
        version: 6.1,
        fullVersion: "6.1",
        [ios]: 6.1
    },
    browser: {
        name: "chrome":
        version: 26.0,
        fullVersion: "26.0.1410.50",
        mode: 26.0,
        fullMode: "26.0.1410.50",
        compatible: false,
        [chrome]: 26.0
    },
    engine: {
        name: "webkit",
        version: 536.26,
        fullVersion: "536.26",
        mode: 523.26,
        fullMode: "523.26",
        compatible: false,
        [webkit]: 536.26
    }
}

Note: Above [iphone], [ios], [chrome], [webkit] is dynamically from actual environment, different device, operation system, browser and rendering engine is different.

Note:

  • This version of detector's code is follow CommonJS sepcification, and support NodeJS and Web Browser environment at the same time.
  • Some times, you just need simple detect a litter information, please reference to #18, without detector.

Installation

via npm:

Installation to global (with -g argument), you can use detector command in terminal.

npm install detector [-g]

via spm:

spm install detector

Usage

Some examples in common use:

// Detect browser name.
detector.browser.name === "chrome" // true

// An other example for detect browser name.
!!detector.browser.ie // false

// Detect the old browseres.
if(detector.browser.ie && detector.browser.version < 8){
    alert("You browser is too old.");
}

// Detect rendering engine below Trident 4 (IE8).
if(detector.engine.trident && detector.engine.mode < 4){
    // hack code.
}

// Collect client detail informations.
detector.browser.name + "/" + detector.browser.fullVersion;

API

{String} detector.device.name

Name of hardware device.

{Number} detector.device.version

Version of hardware device.

{String} detector.device.fullVersion

Full version of hardware device.

{Number} detector.device[device_name]

Detect name of hardware device.

Support hardware devices:

  • pc: Windows PC.
  • mac: Macintosh PC.
  • iphone: iPhone.
  • ipad: iPad.
  • ipod: iPod.
  • android: Android.
  • blackberry: Blackberry mobile.
  • wp: Windows Phone.
  • mi: Xiaomi.
  • meizu: meizu.
  • nexus: Nexus.
  • nokia: Nokia.
  • samsung: samsung.
  • aliyun: Aliyun.
  • huawei: Huawei (华为)
  • lenovo: lenovo.
  • zte: ZTE Corporation (中兴)
  • vivo: vivo (步步高)
  • htc: HTC.
  • oppo: OPPO.
  • konka: konka (康佳)
  • sonyericsson: sonyericsson (索尼爱立信)
  • coolpad: coolpad (酷派)
  • lg: LG.
NODE ONLY

Following hardware device support in NodeJS version of detector:

  • noain: 诺亚信
  • huawei-honor: 华为荣耀
  • lephone: 乐 Phone
  • asus: 华硕
  • alcatel
  • 一加
  • 蓝米
  • E 派
  • hike
  • qmi
  • 友信达: 友信达
  • 优米
  • 嘉源
  • intki
  • 星语
  • 欧奇
  • 海派
  • 广信: 广信
  • nibiru: nibiru
  • 神州
  • 青橙
  • 海信
  • 金立
  • eton
  • bohp
  • 小杨树
  • 语信
  • nubia
  • 爱讯达
  • 寰宇通
  • mofut
  • infocus
  • 大唐
  • 邦华
  • 天迈
  • 大显
  • 博瑞
  • lingwin
  • iusai
  • 波导
  • 德赛
  • 蓝魔
  • 美图
  • opsson
  • benwee
  • hosin
  • smartisan: 锤子, Smartisan.
  • ephone
  • 佰事讯
  • newman
  • konka
  • haier
  • moto
  • tcl
  • 天语
  • doov
  • 天时达

{String} detector.os.name

Name of operation system.

{Number} detector.os.version

Version of operation system.

{String} detector.os.fullVersion

Full version of operation system.

{Number} detector.os[os_name]

Detect name of operation system.

Support operation system list:

  • windows: Windows.
  • macosx: Macintosh.
  • ios: iOS.
  • android: Android.
  • chromeos: Chrome OS.
  • linux: Linux.
  • wp: Windows Phone.
  • windowsce: Windows CE, include Windows Mobile, Smartphone, PPC.
  • symbian: Symbian OS.
  • blackberry: Blackberry OS.
  • yunos: Aliyun OS.
NODE ONLY

Following operation system support in NodeJS version of detector:

  • meego: Meego.
  • smartisan: Smartisan.

{String} detector.browser.name

Name of browser.

{Number} detector.browser.version

Real version of browser.

In compatibility-mode, Internet Explorer declare it is a old browser. but detector.browser.version return the real version of browser.

For example:

IE9 declare it is a IE7 in compatibility-mode, but detector.browser.version return 9.0.

{String} detector.browser.fullVersion

Full (real) version of browser.

{Number} detector.browser.mode

Browser-mode. In Internet Explorer's compatibility-mode, version and mode is different.

{String} detector.browser.fullMode

Full mode of browser.

{Number} detector.browser[browser_name]

Detect name of browser.

Support browser list:

  • edge: Microsoft Edge browser.
  • ie: Microsoft Internet Explorer.
  • chrome: Google Chrome.
  • firefox: Mozilla Firefox.
  • safari: Apple Safari.
  • opera: Opera.
  • 360: Qihu 360 browser.
  • maxthon: Maxthon.
  • sogou: Sogou.
  • theworld: TheWorld.
  • green: GreenBrowser.
  • qq: QQ Browser.
  • tt: TencentTraveler.
  • liebao: Cheetah Mobile Inc. (猎豹) Browser.
  • tao: Taobao (淘宝) Browser.
  • coolnovo: coolnovo (枫树)
  • saayaa: Saayaa (闪游)
  • uc: UC Browser.
  • mi: Build-in browser in Xiaomi (小米).
  • baidu: Baidu (百度) browser.
  • nokia: Build-in Browser in Nokia (诺基亚)
  • blackberry: 黑莓默认浏览器,版本号与系统版本相同。
  • webview: iOS WebView.
  • yandex: Yandex YaBrowser.
  • micromessenger WeChat (微信)
  • ali-ap: 支付宝手机钱包。
  • ali-ap-pd: 支付宝平板客户端。
  • ali-am: 支付宝商户客户端。
  • ali-tb: 淘宝手机客户端。
  • ali-tb-pd: 淘宝平板客户端。
  • ali-tm: 天猫手机客户端。
  • ali-tm-pd: 天猫平板客户端。
NODE ONLY
  • googlebot: Googlebot
  • baiduspider: Baiduspider ,百度无线、网页搜索
  • baiduspider-image: 百度图片搜索
  • baiduspider-video: 百度视频搜索
  • baiduspider-news: 百度新闻搜索
  • baiduspider-favo: 百度收藏搜索
  • baiduspider-cpro: 百度联盟
  • baiduspider-ads: 百度商务搜索
  • baiduboxapp: 百度手机搜索客户端
  • bingbot: Bingbot 网络爬虫。
  • msnbot: MSNBot
  • nuhkbot: Nuhkbot
  • alexabot: Alexabot.
  • curl: curl.
  • slurpbot: Yahoo! Slurp

{Boolean} detector.browser.compatible

Judge is browser in compatibility-mode.


{String} detector.engine.name

Name of rendering engine.

{Number} detector.engine.version

Version of rendering engine.

{String} detector.engine.fullVersion

Full version of rendering engine.

{Number} detector.engine.mode

Mode of rendering engine.

{String} detector.engine.fullMode

Full-mode of rendering engine.

{Number} detector.engine[engine_name]

Detect name of rendering engine.

Support rendering engine list:

  • edgehtml: Microsoft Edge browser's rendering engine. (Note: version same browser version now.)
  • trident: Microsoft Trident.
  • blink: Google Blink.
  • webkit: Apple Webkit.
  • gecko: Mozilla Gecko.
  • presto: Opera Presto.
  • androidwebkit: Android Webkit.
  • coolpadwebkit: Coolpad Webkit.
  • u2: UC browser rendering engine v2.
  • u3: UC browser rendering engine v3.

{detector} detector.parse(String ua)

Parse user agent string, return a detector object.


Not Available information:

  • Not Available name will be na.
  • Not Available version will be -1.

Releases

https://github.com/hotoo/detector/tree/gh-pages

changelog

CHANGELOG


2.4.5 (2016-02-15)

  • fix(smartisan): fixed smartisan device and OS rule. #97.

2.4.4 (2016-02-05)

  • fix(moto): fixed moto rule. #95, #96.

2.4.3 (2016-01-25)

  • fix(ReferenceError): name is not defined. fixed #92

2.4.2 (2015-12-18)

  • fix(theworld): version for the world browser. fixed #90
  • refact(web-node): Web is Web, Node is Node. #87

2.4.1 (2015-09-16)

  • fix(micromessenger): micromessenger rule need before qq browser, because micromessenger use qq browser engine in some Android phone. #84, #85.

2.4.0 (2015-08-23)

  • feat(micromessenger): move wechat support from node to web. #83

2.3.0 (2015-07-30)

  • feat(edge): Add Microsoft Edge browser support. #79 #80

2.2.3 (2015-07-01)

  • feat(browser): package.browser filed.
  • doc(ios): Add iOS code name.
  • doc(alias): Add Mac OS X 10.11 code name.
  • doc(english): Use english document.

2.2.2 (2015-04-22)

  • Fixed #76, 增强了三星手机识别问题。

2.2.1 (2015-02-13)

  • Fixed #75, meizu device rule.
  • Fixed smartisan device and os rules.
  • Update blink engine test case, both available in blink engine and others.
  • Add arale keyword.

2.2.0 (2014-12-18)

  • 15, Add Blink engine.

  • 64, Add 增加了大量的杂牌手机设备 (Node)

  • Fixed nokia and some rules.
  • 37, #43, Delete window.detector global variable.

2.1.2 (2014-12-04)

  • Fixed BlackBerry device, os, and browser rule.
  • Fixed Gecko render engine version number.

2.1.1 (2014-09-22)

  • Update var window to var win for jscoverage.
  • Fixed BaiduHD browser rule.

2.1.0 (2014-09-17)

  • 由于 2.0.2 版修改了部分浏览器名称,可能会有不兼容影响,因此升级次版本号。

2.0.2 (2014-09-17)

  • Add #59 欧朋浏览器 (oupeng)
  • Fixed #56 sogou, liebao, maxthon, baidu 浏览器规则
  • Fixed #60 UC 浏览器规则,支持 UC 桌面版。
  • Update #58 修改 sg, mx, fs, sy 浏览器名称。

2.0.1 (2014-05-13)

  • 调整代码结构,层次更简单。
  • 优化命令行工具,输出更美观。

2.0.0 (2014-05-13)

  • Update: 托 spm@3.x 的福,遵循 CommonJS 规范。同一份源码,不同一个世界。
  • Add: 增加了多个搜索引擎爬虫识别规则。
  • Fixed: 支持 UC 浏览器使用 adr 来标识 Android 设备的规则。
  • Delete: g_detector 全局变量。
  • Update: 更新或优化多个规则,提升了识别准确率。

1.5.0 (2014-05-10)

  • Update: 猎豹浏览器 for iPhone 的识别。
  • Add: 海豚浏览器识别规则。
  • Add: 阿里巴巴系列移动设备客户端的识别。
  • Add: UC 浏览器的 u2, u3 渲染引擎。
  • Fixed: 修复并增强 UC 浏览器的的一些规则。
  • Fixed: vivo 无版本号的识别。

1.4.0 (2014-03-27)

  • Add #11, Yandex browser support.
  • Add #43, window.detector and window.g_detector.

1.3.0 (2013-08-28)

  • Update #37 同时支持 CMD 和非 CMD 模块。但我们强烈建议使用 CMD。

1.2.1 (2013-07-11)

  • Update #27, 附加 navigator.appVersion 和 navigator.vendor 增强识别信息, 更好的支持 UC 浏览器这样特殊的场景。

1.2.0 (2013-07-04)

tag:improved #28, 增强了移动设备的识别。

tag:fixed #29, 修复了猎豹浏览器版本号可能为 undefined 的问题。

tag:fixed #30, 支持最新最贱的 IE11 浏览器。

1.1.3 (2013-06-19)

tag:fixed #25, 支持 iOS 的 WebView。

tag:fixed #26, 部分 UC 浏览器被识别为 Android 的问题。

1.1.2 (2013-06-07)

tag:fixed #24, 规避 external 可能出现的异常。

1.1.1 (2013-05-31)

tag:fixed #17, 修复并增加了 360, theworld, maxthon 等浏览器的识别。

tag:fixed #19, 修复了 Opera Next 的识别问题。

tag:changed 修改 detector.detect() 方法为 detector.parse()

1.1.0 (2013-05-10)

tag:changed #12, 简化版本号的设计。

1.0.1 (2013-05-02)

tag:new 新增了多种客户端识别规则。

tag:fixed 修复 Windows Phone 识别为 Windows 的问题。

1.0.0 (2013-05-01)

tag:new 发布第一个可用版本。