Giter Club home page Giter Club logo

user_agent's Introduction

IMPORTANT: THIS PROJECT HAS MIGRATED TO https://github.com/mssola/useragent

License

Copyright (c) 2012-2023 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.

user_agent's People

Contributors

aksentyev avatar arp242 avatar codelingobot avatar crackcomm avatar cskr avatar danmhammer avatar dlebech avatar dthadi3 avatar dvrkps avatar haoxins avatar jfnadeau avatar kayabe avatar klacointe avatar kshvakov avatar kylekizirian avatar luismulinari avatar mssola avatar nivnadler avatar nono avatar pnelson avatar psilva261 avatar rvflash avatar snackmgmg avatar trentonstrong avatar zhenglu008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

user_agent's Issues

Bingbot parsed as Safari 7.0.

Can you fix the identification of the user agent as Bingbot instead of Safari 7.0?

I parsed Bingbot user-agent information:

package main

import (
	"fmt"
	"github.com/mssola/user_agent"
)

func main() {
	uaInfo := "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
	ua := &user_agent.UserAgent{}
	ua.Parse(uaInfo)
	if ua == nil {
		panic("User Agent parse failed")
	}

	browserName, browserVersion := ua.Browser()
	fmt.Printf("Browser: %+v %+v \n", browserName, browserVersion)
	fmt.Printf("Bot: %+v \n", ua.Bot())
}

It returns:
Browser: Safari 7.0 Bot: false

support edge?

Any chance to get edge support?
An example user agent string looks like:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

Thanks for the cool package :D

Concurrency support?

Does this support concurrent calls? It doesn't look like it, given that New() returns a pointer without a mutex to protect concurrent reads or writes.

This is important in the case of memory use on a web server, for example. I would rather initialize it once and call it repeatedly as opposed to re-initializing it on every client connection, which would end up needlessly adding and removing from the heap as well as increase the amount the garbage collector has to work.

Adding concurrency would simply be a matter of adding a sync.RWMutex field to the UserAgent struct, and calling the UserAgent.RWMutex field's RLock()/RUnlock() or Lock()/Unlock() methods in every library method that reads or writes to the struct, respectively.

0.5.3 Release

👋 @mssola ,

Thanks for maintaining this package! I was wondering when the 0.5.3 release would be made? My use case requires one of the unreleased changes.

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.

panic: runtime error: index out of range

I am getting panic parsing this:

userAgent := &ua.UserAgent{}
userAgent.Parse("Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13")

Provide separate methods for getting OS version and name

It will be nice to have built-in methods for getting OS version and name, rather then split it manually.

UPD. Maybe something like this will be enough

// Returns a string containing the name of the Operating System.
func (p *UserAgent) OSName() string {
    sp := strings.SplitN(p.os, " ", -1)
    sp = sp[:len(sp)-1]
    return strings.Join(sp, " ")
}

// Returns a string containing the version of the Operating System.
func (p *UserAgent) OSVersion() string {
    sp := strings.SplitN(p.os, " ", -1)
    return sp[len(sp)-1]
}

not correct parse SamsungBrowser

UA
Mozilla/5.0 (Linux; Android 8.1.0; SAMSUNG SM-J730FM Build/M1AJQ) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/8.2 Chrome/63.0.3239.111 Mobile Safari/537.36

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

Invalid Facebook User Agents

I have been seeing issues parsing certain user agents from the Facebook app. Most requests from the Facebook app do seem to come prefixed with the browser, etc.. but occasionally I see ones like in my example below.

My feeling is it would be better to leave the browser/version as empty strings in this example. I can probably take a crack at a PR for this soon.

User Agent: [FBAN/FB4A;FBAV/16.0.0.20.15;FBBV/4061184;FBDM/{density=1.5,width=540,height=960};FBLC/en_US;FB_FW/2;FBCR/MY CELCOM;FBPN/com.facebook.katana;FBDV/Lenovo A850+;FBSV/4.2.2;FBOP/1;FBCA/armeabi-v7a:armeabi;]

Browser Name: [FBAN
Browser Version: FB4A;FBAV/195.0.0.35.99;FBBV/128710103;FBDM/{density=1.5,width=540,height=960};FBLC/en_US;FBRV/129521611;FBCR/2degrees;FBMF/samsung;FBBD/samsung;FBPN/com.facebook.katana;FBDV/SM-J250G;FBSV/7.1.1;FBOP/19;FBCA/armeabi-v7a:armeabi;]
&{{BrowserUnknown {0 0 0}} {PlatformUnknown OSUnknown {0 0 0}} DeviceUnknown}

Support for Baiduspider/2.0

Looks like this package does not support Baidu bot: "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"

package main

import "fmt"
import ua "github.com/mssola/user_agent"

func main() {
    userAgent := &ua.UserAgent{}
    userAgent.Parse("Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)")
    fmt.Println(userAgent.Bot())
}

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)

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"
}

Pingdom UA Parsed incorrectly

Example test case:

...
{
	title:    "Pingdom",
	ua:       "Pingdom.com_bot_version_1.4_(http://www.pingdom.com)/",
	expected: "Pingdom:1.4 Browser:Pingdom-1.4 Bot:true Mobile:false",
},
Test     Pingdom
got:     "Browser:Pingdom.com_bot_version_1.4_(http: Bot:true Mobile:false"
expected "Pingdom:1.4 Browser:Pingdom-1.4 Bot:true Mobile:false"

Not really important to fix, just saw it crop up

Firefox w/ MRA in user agent returns MRA as the browser type

Given the following User Agent:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:24.0) Gecko/20130405 MRA 5.5 (build 02842) Firefox/24.0 (.NET CLR 3.5.30729)

The user_agent library returns "MRA" for the browser and an empty browser version.

The expected output is:
Browser: Firefox
Browser Version: 24.0

CriOS is detected as Safari, but with Chrome's version

The browser name is returned as Safari, but the browser-version is returned as 67.0.3396.87 for the following user-agent. The UA belongs to Chrome for iOS.

Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) CriOS/67.0.3396.87 Mobile/15E302 Safari/604.1

A mobile user agent is reported as a non-mobile user agent.

Description

The following ua containing the keyword iPhone wants to be reported as a mobile ua:

Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Jike/7.6.7 /sa-sdk-ios/sensors-verify/track.midway.run?jike

Steps to reproduce

import "github.com/mssola/user_agent"

func main() {
	ua := "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Jike/7.6.7 /sa-sdk-ios/sensors-verify/track.midway.run?jike"
	user_agent.New(ua).Mobile() // True is expected, but false is got.
}

user_agent version

v0.5.2

Go version and interpreter

go version go1.14.2 darwin/amd64

Operating system

macOS Mojave 10.14.6(18G6032)

release a new tagged version

Hello !

Could you release a new tagged version ?
There are many changes since the latest tag: v0.4.1...master

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

Thank you.

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.

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

YandexBot is not detected as a bot on iPhone.

There are several 'User-Agent' kinds of 'YandexBot': https://user-agents.net/bots/yandexbot

The following kind is not detected as a bot:
https://user-agents.net/string/mozilla-5-0-iphone-cpu-iphone-os-8-1-like-mac-os-x-applewebkit-600-1-4-khtml-like-gecko-version-8-0-mobile-12b411-safari-600-1-4-compatible-yandexbot-3-0-http-yandex-com-bots

Steps to reproduce the problem:
var ua user_agent.UserAgent
userAgent := "Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
// Parse a User-Agent inners.
ua.Parse(userAgent)
// Check either a bot or not.
ua.Bot() // == false

Expected result:
ua.Bot() // == true

Verified solution:
`

diff --git a/CHANGELOG.md b/CHANGELOG.md

  • Fix detection of Firefox on iPad.
  • Fix detection of Linux ARM-based Android.
  • Add detection of Chromium Edge on Windows.
    +- Add detection of YandexBot on iPhone.

diff --git a/bot.go b/bot.go

-// Returns true if the info that we currently have corresponds to the Google
+// Returns true if the info that we currently have corresponds to the Google or Yandex
-func (p *UserAgent) googleOrBingBot() bool {
+func (p *UserAgent) googleOrBingBotOrYandex() bool {
// This is a hackish way to detect
// Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.)
// (See https://support.google.com/webmasters/answer/1061943)
// and Bing's mobile bot
// (See https://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0)

  •   if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 {
    
  •   // and Yandex's mobile bot
    
  •   // (See https://yandex.ru/support/webmaster/robot-workings/check-yandex-robots.html)
    
  •   if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 || strings.Index(p.ua, "Yandex") != -1 {
    

diff --git a/operating_systems.go b/operating_systems.go

  •                   _ = p.googleOrBingBot()
    
  •                   _ = p.googleOrBingBotOrYandex()
    
  •                   if !p.googleOrBingBot() && !p.iMessagePreview() {
    
  •                   if !p.googleOrBingBotOrYandex() && !p.iMessagePreview() {
    

`

Google and Mail.Ru bots

Mail.ru bot from networks
188.93.56.0/24
185.30.176.0/23
has user agent
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.2 Safari/537.36

Google proxy bot from networks
66.102.0.0/20
66.249.64.0/19
64.233.160.0/19
has user agent
Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)

Bots not marked as bots

Here is a list of UserAgent strings which are not marked as bots, but in fact they are:

"ADmantX Platform Semantic Analyzer - ADmantX Inc. - www.admantx.com - [email protected]"
"Apache-HttpClient/4.2.3 (java 1.5)"
"Apache-HttpClient/4.3 (java 1.5)"
"Apache-HttpClient/4.3.3 (java 1.5)"
"Application"
"CATExplorador/1.0beta (sistemes at domini dot cat; http://domini.cat/catexplorador.html)"
"COMODOSpider/Nutch-1.2"
"Comodo Spider 1.2"
"Comodo-Webinspector-Crawler 2.1"
"Faraday v0.8.9"
"GigablastOpenSource/1.0"
"GoogleBot 1.0"
"Google_Analytics_Snippet_Validator"
"HTTPClient/1.0 (2.3.4.1, ruby 1.9.3 (2013-06-27))"
"HTTPClient/1.0 (2.4.0, ruby 1.9.3 (2013-06-27))"
"Java/1.6.0_29"
"Java/1.6.0_45"
"Java/1.7.0_09"
"Java/1.7.0_21"
"Java/1.7.0_40"
"Java/1.7.0_60-ea"
"Java/1.7.0_65"
"Mozilla/2.0 (compatible; crw)"
"Mozilla/3.0 (compatible; Indy Library)"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2)"
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDR; .NET4.0C; .NET4.0E; .NET CLR 1.1.4322; Tablet PC 2.0); 360Spider"
"Mozilla/4.0 (compatible; Netcraft Web Server Survey)"
"Mozilla/4.0 (compatible; Synapse)"
"Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
"Mozilla/4.0 (compatible; http://search.thunderstone.com/texis/websearch/about.html)"
"Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)"
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 AlexaToolbar/alxg-3.1"
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1; 360Spider"
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1; 360Spider(compatible; HaosouSpider; http://www.haosou.com/help/help_3_2.html)"
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b"
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) KomodiaBot/1.0"
"Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0 Google (+https://developers.google.com/+/web/snippet/)"
"Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0 Google favicon"
"Mozilla/5.0 (Windows NT 6.2; WOW64) Runet-Research-Crawler (itrack.ru/research/cmsrate; [email protected])"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.13) Gecko/2009073022 Firefox/3.5.2 (.NET CLR 3.5.30729) Survey/2.3 (fr.wsdata.com)"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.13) Gecko/2009073022 Firefox/3.5.2 (.NET CLR 3.5.30729) SurveyBot/2.3 (DomainTools)"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; )  Firefox/1.5.0.11; 360Spider"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.11)  Firefox/1.5.0.11; 360Spider"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11; 360Spider"
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) DumpRenderTree/0.0.0.0 Safari/536.11"
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Web Preview) Chrome/27.0.1453 Safari/537.36"
"Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20100101 Firefox/21.0 WordPress.com mShots"
"Mozilla/5.0 (compatible; Google-Site-Verification/1.0)"
"Mozilla/5.0 (compatible; IstellaBot/1.18.81 +http://www.tiscali.it/)"
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1) (http://name911.com)"
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0); 360Spider"
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0); 360Spider(compatible; HaosouSpider; http://www.haosou.com/help/help_3_2.html)"
"Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0; [email protected])"
"Mozilla/5.0 (compatible; Owler/0.4; +; )"
"Mozilla/5.0 (compatible; PageAnalyzer/1.1;)"
"Mozilla/5.0 (compatible; XML Sitemaps Generator; http://www.xml-sitemaps.com) Gecko XML-Sitemaps/1.0"
"Mozilla/5.0 (compatible; archive.org_bot +http://www.archive.org/details/archive.org_bot)"
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)"
"Mozilla/5.0(compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)"
"Mozilla/5.0(compatible;Sosospider/2.0;+http://help.soso.com/webspider.htm)"
"Porkbun/Mustache (Website Analysis; http://porkbun.com; [email protected])"
"PycURL/7.23.1"
"Python-urllib/1.17"
"Python-urllib/2.6"
"Python-urllib/2.7"
"Python-urllib/3.4"
"Robosourcer/1.0"
"Ruby"
"Sosospider+(+http://help.soso.com/webspider.htm)"
"W3C_Validator/1.3 http://validator.w3.org/services"
"WebTarantula.com Crawler"
"Wget/1.12 (linux-gnu)"
"Wget/1.13.4 (linux-gnu)"
"WhatWeb/0.4.8-dev"
"Who.is Bot"
"WinInet Test"
"YisouSpider"
"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"
"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"curl/7.35.0"
"ip-web-crawler.com"
"panscient.com"
"python-requests/1.1.0 CPython/2.7.4 Linux/3.8.0-19-generic"
"python-requests/1.2.0 CPython/2.7.4 Linux/3.8.0-33-generic"
"python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-24-generic"
"spotinfluence/Nutch-1.4 (Spot Influence crawler; http://spotinfluence.com; hello at spotinfluence dot com)"
"visaduhoc.info Crawler"
"wsr-agent/1.0"

Browser type exported (public), does it need to be?

Description

I found this library (appreciate your OSS contribution) and was looking thru the GoDoc to gain an understanding of the package's API structure.

I was wondering about the Browser type. It's part of the public API, it doesn't seem to be exposed by any of the public functions or as a public field of the other exported types. To me, it appears that this type should not be exported, and should be renamed from Browser to browser.

It's also possible that perhaps that the receiver method:

func (p *UserAgent) Browser() (string, string)

Should instead be exposed as:

func (p *UserAgent) Browser() Browser

What do you think?

Support []byte

It would be great to support byte arrays to pass in the user_agent and get user agent sections as bytes. This would help using fasthttp with this library for performance.

If the user agent is empty, then a panic occurs

I've found a few instances where the useragent isn't sent by the browser. This causes a crash.

I've worked around this by checking first if the useragent is empty, then passing it to user_agent. I'm not sure if it should handle this internally?

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).

Gmail Bot User Agent are not handled as bot

Hi,

We have observed two user agent which are bot or ISP stats but that are not handled by this service

We should include:
User-agent:
~ Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246 Gmail-content-sampling (exact match)
refer: https://stackoverflow.com/questions/63184772/gmail-following-links-gmail-content-sampling
~ via ggpht.com GoogleImageProxy (user agent containing this string)
refer: https://stackoverflow.com/questions/53080761/multiple-calls-from-via-ggpht-com-googleimageproxy-agent

These are two user agent we are handling separately & discarding them as bot

It shall be included as it is tested that these are bot events by Gmail

Thanks in advance for help!

Coc Coc browser UA string is being parsed as Safari

Description

I noticed this Coc Coc browser UA string is being parsed as "Safari".

Steps to reproduce

package main

import (
	"fmt"

	"github.com/mssola/user_agent"
)

func main() {
	ua := user_agent.New("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/96.0.230 Chrome/90.0.4430.230 Safari/537.36")

	name, _ := ua.Browser()
	fmt.Printf("%v\n", name)  // prints "Safari"
}
  • Expected behavior: Browser() name returns "Coc Coc"
  • Actual behavior: Browser() name returns "Safari"

user_agent version

v0.5.3

Go version and interpreter

go version go1.16.6 darwin/amd64

Operating system

Mac OS

Chrome webview

this user agent will receive android 4 for browser name

Mozilla/5.0 (Linux; Android 10; SM-T510 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.120 Safari/537.36 [FB_IAB/FB4A;FBAV/325.0.0.36.170;]

Windows 10

Windows 10 is actually displayed in user agent header as Windows NT 10.0 and not Windows NT 6.4.

Chromium is detected as Safari

specifically, the ua string "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36"

Precompile regex

Instead of compiling the regular expressions on each cycle, you should precompile them for improved performance, i.e.:

Instead of:

reg, _ := regexp.Compile("^rv:(.+)$")

You should declare a global and reusable:

var rvReg = regexp.MustCompile("^rv:(.+)$")

Firefox on Win XP incorrectly marked as Mobile

Hi,

We love this library and are currently using this in production. we detected a bug today in the parsing of firefox's user agent on windows XP:

userAgentXPFF := "Mozilla/5.0 (Windows NT 5.2; rv:31.0) Gecko/20100101 Firefox/31.0"
parsed := user_agent.New(userAgentXPFF)
fmt.Println(parsed.Mobile())

will print true.

i've tracked down the issue to this line:

} else if len(comment) < 3 {
    p.mobile = true
    p.os = "FirefoxOS"

https://github.com/mssola/user_agent/blob/master/operating_systems.go#L116

Please let me know if this issue can be fixed.

Thanks! & great work!

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.