foroco / php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing
MIT License
136 stars 33 forks source link

macOS Monterey not working #9

Open Nexulo opened 3 years ago

Nexulo commented 3 years ago

Hi,

as the title says, it's not detecting macOS Monterey. I have installed macOS Monterey today and it still detect my system as macOS Big Sur.

Best regards maisen20

foroco commented 3 years ago

Hi,

Here is macOS Monterey user-agents examples and it's detectable correctly by latest library version:

Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Mozilla/5.0 (Macintosh; Intel Mac OS X 12.0; rv:93.0) Gecko/20100101 Firefox/93.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15

Can you send me wrong detectable user-agent to make appropriate tests?

Nexulo commented 3 years ago

Hi foroco

Thank you for your fast answer =).

My Infos:

macOS Monterey Version 12.0.1

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15

Browser detection: Array ( [os_type] => desktop [os_family] => macintosh [os_name] => MacOS [os_version] => Big Sur [os_title] => MacOS Big Sur [64bits_mode] => 1 )

foroco commented 3 years ago

Hi, @maisen20

Unfortunately, I have no idea why your Safari 15 browser on macOS Monterey release sends User-Agent as Big Sur release. Because '10_15_7' substring in part of your User-Agent always denotes Big Sur release (according to 'major', 'minor' and 'release' numbers).

I think it's a User-Agent bug in Safari v.15.

Nevertheless, I will continue to try to investigate this issue.

daluu commented 2 years ago

@foroco, for your working case, what browser version are you using? I'm surprised there is a working browser version for detecting Monterey.

Please refer to these for context:

https://www.otsukare.info/2021/02/15/capping-macos-user-agent https://help.duo.com/s/article/6627?language=en_US https://developer.apple.com/forums/thread/666209

with Big Sur onwards, it is expected that the user agent string may not be accurate for reporting actual OS.

the way forward for new OSes is to detect using client hints API for browsers that support it:

https://web.dev/user-agent-client-hints/ https://browserleaks.com/client-hints

The new API doesn't work for all browsers yet. So until the world catches up, the detection for new OSes is best effort.

I wonder if the current Big Sur detection is also accurate, as the issue started/broke with Big Sur, for the newer releases of Big Sur.

DigitalAndSEO commented 2 years ago

The same thing happens to me in Chrome, Safari, Firefox, Opera...

macOS Monterey Version 12.4 M1 processor

( I don't know if @daluu also uses M1 or Intel ) ( Just in case it helps, I use "getAll" )

Chrome Versión 102.0.5005.115 (Build oficial) (arm64): Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

Safari Versión 15.5 (17613.2.7.1.8): Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15

Firefox 101.0.1 (64-bit): Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0

Opera 88.0.4412.40 (arm64): Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.115 Safari/537.36 OPR/88.0.4412.40

foroco commented 1 year ago

Hi,

@daluu Thanks for the links, which show the actuality of the problem.

Unfortunately, after releasing MacOS Big Sur, the OS vendor "froze" the OS User Agent information at that release level.

New MacOS releases no longer send actual OS version information to browsers (tested on WebKit, Chromium, and Gecko-based browser engines).

One solution is to use the User-Agent Client Hints API information on the client side (API information provided by Chromium-based browsers).

daluu commented 1 year ago

I think the server side (PHP) may be able to pull the client hints info, it just requires some extra logic and redirection on the server side perhaps plus maybe some inclusion of client side logic as needed. Because the client hints API between client & server is about server requesting additional info from client (via server HTTP response headers to client's initial hit on the server) and client responding to that server "request" in subsequent HTTP/webpage request, sending them in HTTP request headers, server can then parse those new data. This is only if the browser client supports client hints of course.

https://wicg.github.io/ua-client-hints/#examples https://developer.chrome.com/articles/user-agent-client-hints/#example-exchange

So maybe this project could be extended to offer best effort client hints detection of new OS/browser info? Whether in this main project repo or in a 3rd party project/fork.

daluu commented 1 year ago

( I don't know if @daluu also uses M1 or Intel )

I don't think actual platform/hardware matters for this particular issue. It's all about the OS version that impacts the issue, not even the browser.

foroco commented 1 year ago

I did some tests with client hints. At the moment it's not possible to detect the MacOS version via client hints in the common browsers.

daluu commented 1 year ago

Here is macOS Monterey user-agents examples and it's detectable correctly by latest library version:

Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Mozilla/5.0 (Macintosh; Intel Mac OS X 12.0; rv:93.0) Gecko/20100101 Firefox/93.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15

I'm still curious, @foroco, if you recall where that user agent string came from. Which browser? That string seems to be an anomaly compared to what most of us observe for browsers these days. It would be nice to know for reference, for all of us. Or was that taken from logs received for users that visit the site/page, etc.?

daluu commented 1 year ago

oh, nevermind, I see in the user agent and pasting it in a UA parser it is FF 93. I guess that was a version before FF locked down the OS reporting.

foroco commented 2 months ago

I have been researching this issue:

Unfortunately, the major browser engines have "frozen" the OS version information in the User-Agent header. For example, on macOS, the OS version information in the User-Agent is "frozen" at the macOS Big Sur release level (Mac OS X 10_15_7). On Windows, the OS version information is "frozen" in the User-Agent at the Windows 10 release level (Windows NT 10.0).

Recent releases of WebKit, Chromium, and Gecko-based browsers no longer include current OS version information in the User-Agent header.

See reference:

https://issues.chromium.org/issues/40167872 https://bugzilla.mozilla.org/show_bug.cgi?id=1679929 https://bugs.webkit.org/show_bug.cgi?id=217364

One approach is to use the HTTP Client Hints headers, specifically the Sec-CH-UA-Platform-Version header. It's important to note, however, that only Chromium-based browsers currently support sending Client Hints headers.