51degrees / device-detection-go Goto Github PK
View Code? Open in Web Editor NEWLicense: European Union Public License 1.2
License: European Union Public License 1.2
We've faced with problem.
If browser send Sec-CH-UA-Platform
but not send Sec-CH-UA-Platform-Version
, 51Degrees
won't detect PlatformVersion
. Of course, we requested all Client Hints
headers from browser. Browser decided to send Sec-CH-UA-Platform
only.
For example:
{
"User-Agent": "Mozilla/5.0 (Linux; Android 11; CPH1969) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Mobile Safari/537.36",
"Sec-CH-UA": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"",
"Sec-CH-UA-Mobile": "?1",
"Sec-CH-UA-Platform": "\"Android\""
}
On the other hand, we have enough information to detect Sec-CH-UA-Platform
in User-Agent
:
Enterprise-HashV41.hash
: latest
device-detection-go
: v4.4.3 (latest)
We are using Enterprise-HashV41.hash with golang library.
Latest db (3/21/2022) detects property BrowserName of user-agent Mozilla/5.0 (Linux; Android 11; RMX3261) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.46 Mobile Safari/537.36
as "Chrome".
But on https://51degrees.com/developers/user-agent-tester the same ua is detected as "Chrome Mobile".
As we suggest there is some problem with detection in Enterprise-HashV4 db.
Reproduction order:
Test:
package main
import (
"fmt"
"strings"
"fodegrees/dd"
)
const root = "./"
// User-Agent string of Firefox Web browser version 41 on desktop.
const uaDesktop = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0"
func main() {
var (
path = "resources/51DegreesV4"
files = []string{"51Degrees-LiteV4.1.hash"}
)
manager := dd.NewResourceManager()
filePath, err := dd.GetFilePath(root+path, files)
if err != nil {
panic(err)
}
err = dd.InitManagerFromFile(manager, *dd.NewConfigHash(dd.Balanced), "", filePath)
if err != nil {
panic(err)
}
/* test */
// Get ID based on UserAgent
id, err := getValueFromUserAgent(manager, uaDesktop, "id")
if err != nil {
fmt.Println(err)
}
// Get the correct browser name using the same UserAgent
expectedBrowserName, err := getValueFromUserAgent(manager, uaDesktop, "BrowserName")
if err != nil {
fmt.Println(err)
}
// Tried to get the same browser using the ID
gotBrowserName, err := getValueFromDeviceID(manager, id, "BrowserName")
if err != nil {
fmt.Println(err)
}
// Check that they match
if expectedBrowserName != gotBrowserName {
fmt.Println("ERROR", "expectedBrowserName != gotBrowserName " + expectedBrowserName + " != " + gotBrowserName)
}
/* test with browser id */
// 15364-38914-90352-18092, 15364 - hardwareID, 38914 - OperatingSystemID, 90352 - BrowserID, 18092 - IsCrawler.
browserID := strings.Split(id, string('-'))[2]
gotBrowserName, err = getValueFromDeviceID(manager, browserID, "BrowserName")
if err != nil {
fmt.Println(err)
}
if expectedBrowserName != gotBrowserName {
fmt.Println("ERROR", "expectedBrowserName != gotBrowserName " + expectedBrowserName + " != " + gotBrowserName)
}
}
func getValueFromUserAgent(manager *dd.ResourceManager, userAgent, key string) (res string, err error) {
results := dd.NewResultsHash(manager, 1, 0)
defer results.Free()
err = results.MatchUserAgent(userAgent)
if err != nil {
return
}
res = getValue(results, key)
return
}
func getValueFromDeviceID(manager *dd.ResourceManager, id, key string) (res string, err error) {
results := dd.NewResultsHash(manager, 1, 0)
defer results.Free()
err = results.MatchDeviceId(id)
if err != nil {
return
}
res = getValue(results, key)
return
}
func getValue(results *dd.ResultsHash, propertyName string) string {
if strings.ToLower(propertyName) == "id" {
value, err := results.DeviceId()
if err != nil {
return err.Error()
}
return value
}
// Get the values in string
value, err := results.ValuesString(propertyName, ",")
if err != nil {
return err.Error()
}
hasValues, err := results.HasValues(propertyName)
if err != nil {
return err.Error()
}
if !hasValues {
return "no value"
}
return value
}
At any attempt !hasValue = false, and the value is not returned
Please add Client Hints support for Golang.
It's important because we can't detect Windows 11: https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
For the latest bases I found that there is a strange behaviour in detection of Facebook for Android.
If I use only user-agent header
Mozilla/5.0 (Linux; Android 10; M2006C3LG Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/435.0.0.42.112;]
the detection is
BrowserVendor - Facebook
BrowserName - Facebook for Android
But if I add client-hints headers
sec-ch-ua: "Android WebView";v="117", "Not;A=Brand";v="8", "Chromium";v="117"
sec-ch-ua-mobile: ?1
sec-ch-ua-platform: "Android"
sec-ch-ua-platform-version: "11.0.0"
sec-ch-ua-model: "RMX3231"
sec-ch-ua-full-version: "117.0.5938.153"
sec-ch-ua-full-version-list: "Android WebView";v="117.0.5938.153", "Not;A=Brand";v="8.0.0.0", "Chromium";v="117.0.5938.153"
user-agent: Mozilla/5.0 (Linux; Android 10; M2006C3LG Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/435.0.0.42.112;]
the detection is changing to
BrowserVendor - Google
BrowserName Android Webview
The same happens for online cheker https://51degrees.com/developers/user-agent-tester
I also found, that for detecting FB is generally suggested to use that regexp in js
navigator.userAgent.match(/FBAN|FBAV/i)
.
So I suppose that detection in binary bases of Facebook for Android with CH-headers is working wrong.
Enterprise-HashV41.hash
: latest
device-detection-go
: v4.4.5 (latest)
We have tested device-detection-go in one of our golang projects and it has worked fine so far. We are currently looking for equivalents of the setAutoUpdate
and setShareUsage
methods that we have used in the Java version. Appreciate your help. Thanks
If Sec-CH-UA-Platform
is an integer, 51Degrees
won't detect PlatformVersion
.
For example:
{
"User-Agent": "Mozilla/5.0 (Linux; Android 11; SM-A217M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Mobile Safari/537.36",
"Sec-CH-UA": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"",
"Sec-CH-UA-Full-Version": "\"91.0.4472.164\"",
"Sec-CH-UA-Mobile": "?1",
"Sec-CH-UA-Model": "\"SM-A217M\"",
"Sec-CH-UA-Platform": "\"Android\"",
"Sec-CH-UA-Platform-Version": "\"11\""
}
Changed to 11.0
:
Removed Sec-CH-UA-Platform
+ Sec-CH-UA-Platform-Version
(see #7):
Enterprise-HashV41.hash
: latest
device-detection-go
: v4.4.3 (latest)
Hello, I am using the modified example https://github.com/51Degrees/device-detection-examples-go/blob/main/uach/uach.go to try to detect windows 11. Unfortunately, when setting the headers:
Sec-CH-UA-Platform: Windows
Sec-CH-UA-Platform-Version: 13.0.0
If I install version 10, everything is fine:
The swap is made via:
Can you help me figure it out?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.