detect_browser

detect_browser(useragent: string, [algorithm: const string]?) -> object

Identify the browser used for a web request from its User-Agent header.

Given the contents of a web request User-Agent header string, return the platform/OS and browser/version used to make the request. The input value should not include the User-Agent: header name, only the value.

The optional second argument specifies which browser detection algorithm to use. If no specific algorithm is requested, the default is used. You can also directly request the default with the value "default". The default algorithm may change over time, you may wish to specify your desired algorithm to ensure consistent results.

The supported algorithms are:

algorithmmeaning
defaultUse whatever is the latest and greatest
httpagentparser-1.9.3The Python module httpagentparser, version 1.9.3
lite-2209A simple detector of major bots and browsers

The return value is an object with the following fields:

fieldmeaning
platformAn object describing the source platform. Always returned on non-null input.
platform.nameThe name of the platform -- for example "Windows".
platform.versionThe version of the platform -- for example "10".
botBoolean true, if the agent identifies itself as a web scraper/bot. May be absent.
browserAn object with information about the web browser making the request. May be absent.
browser.nameThe name of the browser -- for example "Chrome".
browser.versionThe version of the browser -- for example "107.0.0.0"
osAn object describing the operating system that made the request. May be absent.
os.nameThe name of the OS, if determined.
flavorAn object with additional information about the requester. May be absent.
flavor.nameThe name of the remote flavor -- for example "MacOS".
flavor.versionThe version of the remote flavor -- for example "X 10.15.7".

If the input is null, the output will be null. Otherwise, at least the platform object is returned, although the name and/or version may be null individually, depending on how much information could be extracted from the header value. The other objects are returned only if the remote user-agent matches the specifics, with most variation in os and flavor whereas browser and platform are more consistent.

Note that scripts and attacks can easily forge the User-Agent header, so this information is largely helpful when analyzing legitimate traffic, or in conjunction with other fingerprints extracted from the request.

Domain

This is a scalar function (calculates a single output value for a single input row).

Categories

Examples

make_col browser:detect_browser(headers['user-agent'])

Assuming there is an object input column headers with the headers from a web request, look up the header user-agent and make the column browser with information about the requester.

user-agentbrowser
nullnull
some random text{ platform: { name: null, version: null } }
Mozilla/5.0 (Windows 11.0) Chrome/105.0.0.0{ platform: { name: "Windows", "version": "11.0" }, os: { name: "Windows", version: "11.0" }, bot: false, browser: { name: "Chrome", version: "105.0.0.0" } }