HTTP User Agent parser for the Go programming language.

Build Status for master branch godoc.org page MIT


UserAgent is a Go library that parses HTTP User Agents. As an example:

package main

import (
    "fmt"

    "github.com/mssola/user_agent"
)

func main() {
    // The "New" function will create a new UserAgent object and it will parse
    // the given string. If you need to parse more strings, you can re-use
    // this object and call: ua.Parse("another string")
    ua := user_agent.New("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11")

    fmt.Printf("%v\n", ua.Mobile())   // => false
    fmt.Printf("%v\n", ua.Bot())      // => false
    fmt.Printf("%v\n", ua.Mozilla())  // => "5.0"

    fmt.Printf("%v\n", ua.Platform()) // => "X11"
    fmt.Printf("%v\n", ua.OS())       // => "Linux x86_64"

    name, version := ua.Engine()
    fmt.Printf("%v\n", name)          // => "AppleWebKit"
    fmt.Printf("%v\n", version)       // => "537.11"

    name, version = ua.Browser()
    fmt.Printf("%v\n", name)          // => "Chrome"
    fmt.Printf("%v\n", version)       // => "23.0.1271.97"

    // Let's see an example with a bot.

    ua.Parse("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")

    fmt.Printf("%v\n", ua.Bot())      // => true

    name, version = ua.Browser()
    fmt.Printf("%v\n", name)          // => Googlebot
    fmt.Printf("%v\n", version)       // => 2.1
}

If you want to read the full API documentation simply check godoc.

Installation

go get -u github.com/mssola/user_agent

Contributing

Do you want to contribute with code, or to report an issue you are facing? Read the CONTRIBUTING.md file.

Changelog

Read the CHANGELOG.md file.

License

Copyright (c) 2012-2021 Miquel Sabaté Solà

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Owner
Miquel Sabaté Solà
Free software developer. Working with containers @SUSE.
Miquel Sabaté Solà
Comments
  • Adds the Adsense bot (mobile)

    Adds the Adsense bot (mobile)

    According to the following list of Google crawlers, I have changed the detection of Google mobile crawlers to deal with the one of Google Ads.

    Google crawlers (user agents)

  • Edge Detecting as Chrome

    Edge Detecting as Chrome

    In using this on the Mattermost project we have found that it detects Edge as Chrome. I'm not sure if it's limited to a certain version of Edge or all Edge versions. The version I'm running is Edge 38.xxxx (EdgeHTML 14.xxx). It's detecting as Chrome 51.

    Is this a known issue or bug? Either way can we do anything to help resolve it? Thanks.

  • Shorter Linux tagging

    Shorter Linux tagging

    Question: Currently, Linux is being tagged as "Linux x86_64" for the OS part. It would be nice if it was just "Linux". I'll be happy to write up little PR for this, but I just wanted your opinion on it first.

    One proposal for a solution would be to check if "Linux" appears in the OS name and then split on any spaces and take the first part. I don't know if this would work for all Linux variants.

  • Fix detection of Firefox on iPad

    Fix detection of Firefox on iPad

    Provide a general description of the changes in your pull request. If this pull request fixes a known issue, please tag it as well (e.g.: Fixes #1).

    Before submitting a PR make sure the following things have been done (and denote this by checking the relevant checkboxes):

    • [X] The commits are consistent with the contribution guidelines.
    • [X] You've added tests (if possible) to cover your change(s).
    • [X] All tests and style checkers are passing (make ci).
    • [X] You've updated the changelog.
    • [ ] You've updated the readme (if relevant).

    Thanks for contributing to user_agent!

  • Add additional WebKit browsers

    Add additional WebKit browsers

    Add support for the following:

    • Coc Coc Browser
    • Headless Chrome
    • iOS WebViews

    Fixes #82

    Before submitting a PR make sure the following things have been done (and denote this by checking the relevant checkboxes):

    • [x] The commits are consistent with the contribution guidelines.
    • [x] You've added tests (if possible) to cover your change(s).
    • [x] All tests and style checkers are passing (make ci).
    • [x] You've updated the changelog.
    • [x] You've updated the readme (if relevant).
  • Support of Microsoft Edge is missing

    Support of Microsoft Edge is missing

    Description

    Support of Microsoft Edge is missing

    Steps to reproduce

    1. Get UA from Microsoft Edge
    • Browser name = "Edge"
    • currently getting Browser name = "Chrome"

    user_agent version

    With a git commit SHA if possible.

    Go version and interpreter

    $ go version
    

    Operating system

    The operating system and the exact version you are using. If you are using Linux, it may be useful to know which distribution you are using and what did you do in order to install go.

  • release a new tagged version

    release a new tagged version

    Hello !

    Could you release a new tagged version ? There are many changes since the latest tag: https://github.com/mssola/user_agent/compare/v0.4.1...master

    Do you have any plan to release future tags more frequently ? Do you use semver ?

    Thank you.

  • Add support for IE compatibility Trident tokens.

    Add support for IE compatibility Trident tokens.

    I had a few users that are apparently in IE 7 compatibility mode on IE 8 and IE 10. I had to look this up but apparently for IE 8, 9, and 10, the Trident token is a more reliable representation of browser version.

    http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx#VerToken http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx#TriToken

    Warning: The Tablet test had MSIE 7.0 and Trident/6.0. According to the document above, this should be IE 10 but it was being tested for IE 7. I've made the change in this commit.

  • panic: runtime error: index out of range

    panic: runtime error: index out of range

    More user agents that panic:

    Mozilla/5.0 (Linux; U) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
    Mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    
  • panic: runtime error: index out of range

    panic: runtime error: index out of range

    Another panic parsing this:

    userAgent := &ua.UserAgent{}
    userAgent.Parse("Opera/9.80 (Windows NT 6.0; WOW64) Presto/2.12.388 Version/12.15")
    
  • Electron Support

    Electron Support

    When Electron Apps(https://electron.atom.io/) are used it detects strangely. I'm on a mac and it's detecting electron apps as Safari, but then it's detecting the version of Safari not as the actual Safari version, nor the version of Electron, but the version of the app.

    Franz detects as:

    [2017/09/15 16:36:38 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Franz/4.0.4 Chrome/52.0.2743.82 Electron/1.3.1 Safari/537.36
    [2017/09/15 16:36:38 PDT] [DEBG] Detected Client: Safari 4.0.4
    

    The Mattermost App Detects as:

    [2017/09/15 16:37:16 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Mattermost/3.7.1 Chrome/56.0.2924.87 Electron/1.6.11 Safari/537.36
    [2017/09/15 16:37:16 PDT] [DEBG] Detected Client: Mattermost App - Safari 3.7.1
    

    I'm not entirely sure how electron works but it seems like I should either be give Electron as the Browser and the Version of Electron in use, or if electron is simply using a Safari Window then the correct version of Safari (or the windows/linux browser counterpart).

  • Browser Name Incorrect

    Browser Name Incorrect

    Following is the agent that I'm using

    Mozilla/5.0 (Windows NT 6.1; lzh-TW; rv:1.9.0.20) Gecko/2021-03-10 02:14:35 Firefox/3.6.20
    

    When I do this, I get the name of the Browser as 02:14:35. However, when I use the parser here

    https://user-agents.net/parser

    then I get the browser correctly as firefox

        "parent": "Firefox 3.6",
        "browser_bits": "32",
        "platform": "Win7",
        "platform_version": "6.1",
        "platform_description": "Windows 7",
        "platform_bits": "32",
        "platform_maker": "Microsoft Corporation",
        "win64": "false",
        "comment": "Firefox 3.6",
        "browser": "Firefox",
        "browser_type": "Browser",
        "browser_maker": "Mozilla Foundation",
        "frames": "true",
        "iframes": "true",
        "tables": "true",
        "cookies": "true",
        "javascript": "true",
        "cssversion": "3",
        "device_name": "Windows Desktop",
        "device_type": "Desktop",
        "device_pointing_method": "mouse",
        "device_code_name": "Windows Desktop",
        "renderingengine_name": "Gecko",
        "renderingengine_description": "For Firefox, Camino, K-Meleon, SeaMonkey, Netscape, and other Gecko-based browsers.",
        "renderingengine_maker": "Mozilla Foundation",
        "browser_modus": "",
        "version": "3.6",
        "majorver": "3",
        "minorver": "6",
        "alpha": "false",
        "beta": "false",
        "win16": "false",
        "win32": "true",
        "backgroundsounds": "false",
        "vbscript": "false",
        "javaapplets": "true",
        "activexcontrols": "false",
        "ismobiledevice": "false",
        "istablet": "false",
        "issyndicationreader": "false",
        "crawler": "false",
        "isfake": "false",
        "isanonymized": "false",
        "ismodified": "false",
        "aolversion": "",
        "device_maker": "",
        "device_brand_name": "",
        "renderingengine_version": "1.9.2"
    }
    
  • Identifying text-only browsers (lynx, links, elinks, dillo)

    Identifying text-only browsers (lynx, links, elinks, dillo)

    Would you be open to adding appropriate functionality to detect various commonly (still used today) Text-only browsers such as (to name a few):

  • [NEW] Detect Device Details with Detective API

    [NEW] Detect Device Details with Detective API

    Hello Devs,

    Detecting the device details of your users is now easier than ever with Detective API. Our API is powered by AI and makes detecting devices easy and effortless. Check it out

  • HeadlessChrome ua parse error

    HeadlessChrome ua parse error

    Description

    HeadlessChrome ua parse error

    Steps to reproduce

    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/97.0.4691.0 Safari/537.36

    image

    • Expected behavior: browser.name is HeadlessChrome
    • Actual behavior: browser.name is Safari

    user_agent version

    v0.5.3

    Go version and interpreter

    go version go1.17.6 linux/amd64

    Operating system

    debian 11

  • PhantomJS user agent

    PhantomJS user agent

    Description

    The user agent name for PhantomJS is being reported as Safari when it probably should be PhantomJS.

    Steps to reproduce

    Get name value of PhantomJS user agent: Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1

    • Expected behavior: user agent name is PhantomJS
    • Actual behavior: user agent name is Safari

    user_agent version

    0.5.3

    Go version and interpreter

    1.16.6

    Code example

    package main
    
    import (
    	"fmt"
    
    	"github.com/mssola/user_agent"
    )
    
    func main() {
    	ua := user_agent.New(
    		"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1")
    
    	name, _ := ua.Browser()
    	fmt.Printf("%v\n", name) // This should be "PhantomJS" instead of "Safari"
    }
    

    Golang playground example: https://play.golang.org/p/2cXcLn1Kzi3

Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

Jul 14, 2021
Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

Oct 7, 2022
fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client.

fhttp The f stands for flex. fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client. T

Jan 1, 2023
NATS HTTP Round Tripper - This is a Golang http.RoundTripper that uses NATS as a transport.

This is a Golang http.RoundTripper that uses NATS as a transport. Included is a http.RoundTripper for clients, a server that uses normal HTTP Handlers and any existing http handler mux and a Caddy Server transport.

Dec 6, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Jan 17, 2022
Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Feb 1, 2022
Full-featured, plugin-driven, extensible HTTP client toolkit for Go

gentleman Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go. gentleman embr

Dec 23, 2022
An enhanced http client for Golang
An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Dec 23, 2022
An enhanced HTTP client for Go
An enhanced HTTP client for Go

Heimdall Description Installation Usage Making a simple GET request Creating a hystrix-like circuit breaker Creating a hystrix-like circuit breaker wi

Jan 9, 2023
Enriches the standard go http client with retry functionality.

httpRetry Enriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface. The advantage of this libra

Dec 10, 2022
Go (golang) http calls with retries and backoff

pester pester wraps Go's standard lib http client to provide several options to increase resiliency in your request. If you experience poor network co

Dec 28, 2022
http client for golang
http client for golang

Request HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd

Dec 18, 2022
Simple HTTP and REST client library for Go

Resty Simple HTTP and REST client library for Go (inspired by Ruby rest-client) Features section describes in detail about Resty capabilities Resty Co

Jan 1, 2023
A nicer interface for golang stdlib HTTP client

rq A nicer interface for golang stdlib HTTP client Documents rq: here client: here jar: here Why? Because golang HTTP client is a pain in the a... Fea

Dec 12, 2022
A Go HTTP client library for creating and sending API requests
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Jan 7, 2023
HTTP Load Testing And Benchmarking Tool

GBench HTTP Load Testing And Benchmarking Tool inspired by Apache Benchmark and Siege. Requirements You need Golang installed and ready on your system

Jan 2, 2020
HTTP/HTTPS load testing and benchmarking tool

Introduction I wrote that code because: (the obvious reason::I love to write code in Go) We are working so hard to optimize our servers - why shouldn'

Dec 5, 2022
An HTTP proxy library for Go

Introduction Package goproxy provides a customizable HTTP proxy library for Go (golang), It supports regular HTTP proxy, HTTPS through CONNECT, and "h

Jan 4, 2023
Useful HTTP middlewares

This project contains middlewares that I often found myself reimplementing in new projects. In addition, it includes a middleware that logs in a forma

Apr 16, 2022