Wraps the uadetector UserAgentStringParser to parse browser user agent strings into structured details such as browser name, version and operating system, exposing this to server-side JavaScript. An app can call this directly with a user agent string, or use the convenience methods that parse the user agent header of the current request.
Properties
| Property | Returns | Description |
|---|---|---|
| userAgent | ReadableUserAgent | Parses the user agent header of the current request, if there is one. Returns null when there is no current request or the request has no user agent header. |
| userAgentAsJson | String | Parses the user agent header of the current request, if there is one, and returns the result as a JSON string. Returns null when there is no current request or the request has no user agent header. |
| userAgentAsJsonObject | JSONObject | Parses the user agent header of the current request, if there is one, and returns the result as a JSON object. Returns null when there is no current request or the request has no user agent header. |
Methods
parse(String userAgent)
Returns: ReadableUserAgent
Parses a user agent string, for example "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", into a structured ReadableUserAgent.
| Parameter | Description |
|---|---|
userAgent | the raw user agent string to parse |
parseAsJson(String userAgent)
Returns: String
Parses the given user agent string and returns the result as a JSON string.
| Parameter | Description |
|---|---|
userAgent | the raw user agent string to parse |
parseAsJsonObject(String userAgent)
Returns: JSONObject
Parses the given user agent string and returns the result as a JSON object.
| Parameter | Description |
|---|---|
userAgent | the raw user agent string to parse |
getUserAgent()
Returns: ReadableUserAgent
Parses the user agent header of the current request, if there is one. Returns null when there is no current request or the request has no user agent header.
getUserAgentAsJsonObject()
Returns: JSONObject
Parses the user agent header of the current request, if there is one, and returns the result as a JSON object. Returns null when there is no current request or the request has no user agent header.
getUserAgentAsJson()
Returns: String
Parses the user agent header of the current request, if there is one, and returns the result as a JSON string. Returns null when there is no current request or the request has no user agent header.