@@ -19,17 +19,60 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
19
19
* Source : https://github.com/faisalman/ua-parser-js
20
20
21
21
# 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"] ` .
22
30
23
- ## Constructor
24
31
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:
25
35
* ` 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
+ ```
27
50
51
+ When you call UAParser without the ` new ` keyword, it will automatically call ` getResults() ` function and return the parsed results.
28
52
* ` UAParser([uastring][,extensions]) `
29
53
* returns result object ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } `
30
54
31
55
## Methods
32
56
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
+
33
76
* ` getBrowser() `
34
77
* returns ` { name: '', version: '' } `
35
78
@@ -38,17 +81,18 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
38
81
2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
39
82
BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
40
83
Chrome 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...
52
96
53
97
# 'browser.version' determined dynamically
54
98
```
@@ -60,6 +104,13 @@ Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
60
104
# Possible 'device.type':
61
105
console, mobile, tablet, smarttv, wearable, embedded
62
106
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
+
63
114
# Possible 'device.vendor':
64
115
Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT& T, BenQ, BlackBerry, Dell,
65
116
Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
@@ -88,11 +139,12 @@ NetSurf, Presto, Tasman, Trident, w3m, WebKit
88
139
# Possible 'os.name'
89
140
AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
90
141
Contiki, 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, ...
96
148
97
149
# 'os.version' determined dynamically
98
150
```
@@ -105,9 +157,6 @@ SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile],
105
157
68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
106
158
```
107
159
108
- * ` getResult() `
109
- * returns ` { ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} } `
110
-
111
160
* ` getUA() `
112
161
* returns UA string of current instance
113
162
@@ -191,6 +240,8 @@ SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile],
191
240
192
241
## Using node.js
193
242
243
+ Note: Device information is not available in the NodeJS environment.
244
+
194
245
``` sh
195
246
$ npm install ua-parser-js
196
247
```
0 commit comments