You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 =newUAParser("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.
0 commit comments