6.10.94-stable

Useragent

available since: 7.0

@library("useragent", "0.0.0");

This library contains a utility method to parse User Agent strings often stored inside web log files.

Hereafter is a simple example of usage:

@library("useragent", "0.0.0");
use useragent;
fn main() {
    println(UserAgent::parse("Mozilla/5.0 (Linux; Android 4.4.2; QMV7A Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Safari/537.36"));
}

Replace the version “0.0.0” with the appropriate one you find here. Then run

greycat install
greycat run

Output should be the following:

UserAgent{
    browserFamily:"Chrome",
    browserMajor:"36",
    browserMinor:"0",
    browserPatch:"1985",
    osFamily:"Android",
    osMajor:"4",
    osMinor:"4",
    osPatch:"2",
    osPatchMinor:null,
    deviceFamily:"QMV7A",
    deviceBrand:"Generic_Android_Tablet",
    deviceModel:"QMV7A"
}

The library parses a string containing the user agent fingerprint, and returns a UserAgent instance with the following split attributes:

  • browserFamily: String?: The browser name of the user agent, For example Chrome
  • browserMajor: String?: The browser major version, example: 36
  • browserMinor: String?: The browser minor version, example: 0
  • browserPatch: String?: The browser patch version version, example: 1985
  • osFamily: String?: The OS main name, example: Android
  • osMajor: String?: The OS major version, example: 4
  • osMinor: String?: The OS minor version, example: 4
  • osPatch: String?: The OS patch number, example: 2
  • osPatchMinor: String?: The OS minor patch number, example: 4
  • deviceFamily: String?: The Device name, example: iPhone
  • deviceBrand: String?: The Device brand, example: Apple
  • deviceModel:String?: The Device model, example: 11