@@ -19,17 +19,60 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
1919* Source : https://github.com/faisalman/ua-parser-js
2020
2121# Documentation
22+ ### UAParser([ user-agent] [ ,extensions ] )
23+ typeof ` user-agent ` "string".
24+
25+ typeof ` extensions ` "array".
26+
27+ In The Browser environment you dont need to pass the user-agent string to the function, you can just call the funtion and it should automatically get the string from the ` window.navigator.userAgent ` , but that is not the case in nodejs. The user-agent string must be passed in nodejs for the function to work.
28+ Usually you can find the user agent in:
29+ ` request.headers["user-agent"] ` .
2230
23- ## Constructor
2431
32+ ## Constructor
33+ When you call ` UAParser ` with the ` new ` keyword ` UAParser ` will return a new instance with an empty result object, you have to call one of the available methods to get the information from the user-agent string.
34+ Like so:
2535* ` new UAParser([uastring][,extensions]) `
26- * returns new instance
36+ ``` js
37+ let parser = new UAParser (" user-agent" ); // you need to pass the user-agent for nodejs
38+ console .log (parser); // {}
39+ let parserResults = parser .getResults ();
40+ console .log (parserResults);
41+ /** {
42+ "ua": "",
43+ "browser": {},
44+ "engine": {},
45+ "os": {},
46+ "device": {},
47+ "cpu": {}
48+ } */
49+ ```
2750
51+ When you call UAParser without the ` new ` keyword, it will automatically call ` getResults() ` function and return the parsed results.
2852* ` UAParser([uastring][,extensions]) `
2953 * returns result object ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } `
3054
3155## Methods
3256
57+ #### Methods table
58+ The methods are self explanatory, here's a small overview on all the available methods:
59+ * ` getResult() ` - returns all function object calls, user-agent string, browser info, cpu, device, engine, os:
60+ ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } ` .
61+
62+ * ` getBrowser() ` - returns the browser name and version.
63+ * ` getDevice() ` - returns the device model, type, vendor.
64+ * ` getEngine() ` - returns the current browser engine name and version.
65+ * ` getOS() ` - returns the running operating system name and version.
66+ * ` getCPU() ` - returns CPU architectural design name.
67+ * ` getUA() ` - returns the user-agent string.
68+ * ` setUA(user-agent) ` - set a custom user-agent to be parsed.
69+
70+
71+ ---
72+
73+ * ` getResult() `
74+ * returns ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } `
75+
3376* ` getBrowser() `
3477 * returns ` { name: '', version: '' } `
3578
@@ -38,17 +81,18 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
38812345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
3982BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
4083Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
41- Dolphin, Doris, Edge, Electron, Epiphany, Facebook, Falkon, Fennec, Firebird,
42- Firefox [Reality], Flock, Flow, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe,
43- IceCat, IceDragon, Iceweasel, Instagram, Iridium, Iron, Jasmine, K-Meleon,
44- Kindle, Klar, Konqueror, LBBROWSER, Line, Links, Lunascape, Lynx, MIUI Browser,
45- Maemo Browser, Maemo, Maxthon, MetaSr Midori, Minimo, Mobile Safari, Mosaic,
46- Mozilla, NetFront, NetSurf, Netfront, Netscape, NokiaBrowser, Obigo, Oculus Browser,
47- OmniWeb, Opera Coast, Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix,
48- Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari,
49- Sailfish Browser, Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim,
50- SlimBrowser, Swiftfox, Tesla, Tizen Browser, UCBrowser, UP.Browser, Vivaldi,
51- Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
84+ Dolphin, Doris, DuckDuckGo, Edge, Electron, Epiphany, Facebook, Falkon, Fennec,
85+ Firebird, Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, Huawei Browser,
86+ ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceweasel, Instagram,
87+ Iridium, Iron, Jasmine, K-Meleon, Kindle, Klar, Konqueror, LBBROWSER, Line,
88+ LinkedIn, Links, Lunascape, Lynx, MIUI Browser, Maemo Browser, Maemo, Maxthon,
89+ MetaSr Midori, Minimo, Mobile Safari, Mosaic, Mozilla, NetFront, NetSurf, Netfront,
90+ Netscape, NokiaBrowser, Obigo, Oculus Browser, OmniWeb, Opera Coast,
91+ Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix, Polaris, Puffin, QQ,
92+ QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari, Sailfish Browser,
93+ Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim, SlimBrowser, Swiftfox,
94+ Tesla, Tizen Browser, UCBrowser, UP.Browser, Vivaldi, Waterfox, WeChat, Weibo,
95+ Yandex, baidu, iCab, w3m, Whale Browser...
5296
5397# 'browser.version' determined dynamically
5498```
@@ -60,6 +104,13 @@ Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
60104# Possible 'device.type':
61105console, mobile, tablet, smarttv, wearable, embedded
62106
107+ # #########
108+ # NOTE: 'desktop' is not a possible device type.
109+ # UAParser only reports info directly available from the UA string, which is not the case for 'desktop' device type.
110+ # If you wish to detect desktop devices, you must handle the needed logic yourself.
111+ # You can read more about it in this issue: https://github.com/faisalman/ua-parser-js/issues/182
112+ # #########
113+
63114# Possible 'device.vendor':
64115Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT& T, BenQ, BlackBerry, Dell,
65116Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
@@ -88,11 +139,12 @@ NetSurf, Presto, Tasman, Trident, w3m, WebKit
88139# Possible 'os.name'
89140AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
90141Contiki, Fedora, Firefox OS, FreeBSD, Debian, Deepin, DragonFly, elementary OS,
91- Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HP-UX, Hurd, iOS, Joli, KaiOS, Linpus, Linspire,
92- Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix, Mint, Morph OS, NetBSD,
93- Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX,
94- Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon, Sailfish, Series40, Slackware, Solaris,
95- SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
142+ Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HarmonyOS, HP-UX, Hurd, iOS, Joli, KaiOS,
143+ Linpus, Linspire,Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix,
144+ Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS,
145+ Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon,
146+ Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, Unix,
147+ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
96148
97149# 'os.version' determined dynamically
98150```
@@ -105,9 +157,6 @@ SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile],
10515768k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
106158```
107159
108- * ` getResult() `
109- * returns ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } `
110-
111160* ` getUA() `
112161 * returns UA string of current instance
113162
@@ -191,6 +240,8 @@ SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile],
191240
192241## Using node.js
193242
243+ Note: Device information is not available in the NodeJS environment.
244+
194245``` sh
195246$ npm install ua-parser-js
196247```
0 commit comments