totpero / DeviceDetector.NET

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Apache License 2.0
343 stars 72 forks source link

User-Agent string changed in Chrome causing undetectable device #71

Closed marcelo-qrplus closed 1 year ago

marcelo-qrplus commented 1 year ago

Since Octuber-2022, Chrome has been reducing User-Agent string and now on May-2023 change it dramaticaly, causing undetectable device using this lib.

Source: https://developer.chrome.com/blog/user-agent-reduction-oct-2022-updates/

I will try to fix, but if anyone already know this lib and can do it faster, it would be great.

Tks, MC

totpero commented 1 year ago

Hi @marcelo-qrplus We already have implemented User Agent Client Hint. Try to do something like this to set the CH from your request into your code:

DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);

ar userAgent = Request.Headers["User-Agent"]; // change this to the useragent you want to parse
var headers = Request.Headers.ToDictionary(a => a.Key, a => a.Value.ToArray().FirstOrDefault());
var clientHints = ClientHints.Factory(headers);  // client hints are optional

var dd = new DeviceDetector(userAgent,clientHints);
//var result = DeviceDetector.GetInfoFromUserAgent(userAgent, clientHints);
marcelo-qrplus commented 1 year ago

Nice tip!! Worked...sorry, I didn't know that!! Tks @totpero