Coder Social home page Coder Social logo

device-detection-go's People

Contributors

antonypost avatar automation51d avatar ben51degrees avatar drasmart avatar inetjojo avatar justadreamer avatar jwrosewell avatar pi-alexander-popel avatar sarana-anna avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

device-detection-go's Issues

User-Agent as fallback for Client Hints

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

image

On the other hand, we have enough information to detect Sec-CH-UA-Platform in User-Agent:

image

Enterprise-HashV41.hash: latest
device-detection-go: v4.4.3 (latest)

Bad detection of Chrome Mobile

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.

Cannot get property using Device ID

Reproduction order:

  1. Get Device ID using UserAgent
  2. Using Device ID, or part of it, try to get BrowserName or HardwareVendor value

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

Facebook for Android Detection

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)

Doesn't detect PlatformVersion for Android in some cases

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

image

Changed to 11.0:

image

Removed Sec-CH-UA-Platform + Sec-CH-UA-Platform-Version (see #7):

image

Enterprise-HashV41.hash: latest
device-detection-go: v4.4.3 (latest)

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.