faisalman / ua-parser-js

"Unmask Your Traffic" - UAParser.js: The Essential Web Development Tool for User-Agent Detection
https://uaparser.dev/
GNU Affero General Public License v3.0
9.28k stars 1.2k forks source link

Wrong Mac OS version - 10.15.7 #659

Open piotrzarzycki21 opened 1 year ago

piotrzarzycki21 commented 1 year ago

Describe the bug Script reports wrong Mac OS version.

To Reproduce Steps to reproduce the behavior: I'm calling method getOS() and result is:

Screenshot 2023-06-09 at 09 17 40

Expected behavior My Mac OS version is Ventura 13.4. I should get in returned object:

{
   name: "Mac OS"
   version: "13.4"
}

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

hzj002 commented 1 year ago

has this issue too

leoh7 commented 1 year ago

Have you checked your actual 'request headers'? I also have this problem, but I don't think it pertains to a library issue. My actual OS and 'User-Agent' appear as follows. Left: request headers | right: system info

image

Qrivi commented 1 year ago

I encounter the same issue, also on macOS 13.4.1 and my user agent reporting 10_15_7. I do think it's a bug though: if I load the demo website, it correctly parses as 13.4.1 but in my project, it doesn't.

However, if I copy my user agent on the demo website using that purple "copy to clipboard" button, then paste it in below where it says "or type any User-Agent you want to check" and check, it also incorrectly parses as 10.5.7 (despite being the same UA as parsed on page load).

Edit: also on page load the cpu object has an architecture key with value arm64 for me (M1 Pro), but on checking the same user agent again (and in my project), cpu is an empty object.

JamesBream commented 1 year ago

@Qrivi The demo site is using 2.0.0-alpha.2 version which is probably why you're seeing different behaviour between it and your own project.

The short of it is that the major browsers decided not to bump the macOS version from 10.15.7 to 11.0.0 because of a (now fixed) bug in Unity sites. Chrome supports client hints which the 2.0.0 version of this library can use to determine version info, but for Safari and Firefox (maybe others?) there's no support for client hints and no intention to bump the UA version numbers any further as it stands. Nothing this library can really do about it unfortunately.

thomasvanhorde commented 1 year ago

Try this UAParser().withClientHints().then(function(result) { .. })

Qrivi commented 1 year ago

Thanks for the explanation @JamesBream and the snippet @thomasvanhorde. Unfortunately, this won't work for our current implementation as we are parsing a bunch of user agents we get from our (non-js) backend to display a list of active sessions for the current user. I haven't checked if you can pass user hints to ua-parser (vs it can only read the current browser's hints) but even if so, we'd have to store them in the backend too then.

I was not aware client hints were a thing tbh, so we are going to re-evaluate how we can log and display a user's active session as we already did some "beautifying" on top of ua-parser-js like changing Mactintosh to macOS (and 10.15.7 to 13.4 ;) ). In our case it might make more sense to parse user agent and client hints headers on the backend and have our endpoint return the formatted string, no further parsing required. To be seen what is possible and what makes most sense. :)

faisalman commented 1 year ago

You can also read client hints data from back-end by sending Accept-CH / Critical-CH header as a response:


// express
app.get('/test', (req, res) => {

    // Please send us your Platform (OS) data!
    const requiredHints = "Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version";
    res.setHeader('Accept-CH', requiredHints);
    res.setHeader('Critical-CH', requiredHints);

    UAParser(req.headers).withClientHints().then(res => {
        console.log(res);
    });
    res.sendStatus(200);
});
faisalman commented 1 year ago

This issue is primarily caused by macOS version being capped at 10.15.7 on all major browsers:

piotrzarzycki21 commented 1 year ago

@Qrivi The demo site is using 2.0.0-alpha.2 version which is probably why you're seeing different behaviour between it and your own project.

The short of it is that the major browsers decided not to bump the macOS version from 10.15.7 to 11.0.0 because of a (now fixed) bug in Unity sites. Chrome supports client hints which the 2.0.0 version of this library can use to determine version info, but for Safari and Firefox (maybe others?) there's no support for client hints and no intention to bump the UA version numbers any further as it stands. Nothing this library can really do about it unfortunately.

@JamesBream Even if I'm trying 2.0.0-alpha.2 in my application it pointing me wrong version of OSX in Brave browser while your website showing correct one. I'm on Mac OS Sonoma 14.0. Should 2.0.0-alpha.2 work in at least Brave or Chrome ?

mehagar commented 11 months ago

In theory, in lieu of the User Agent Client Hints API, it would be possible to determine the OS on Safari/Firefox based on feature detection, in cases where a feature is only supported on one OS but not another. For example, testing for WebGL in Workers, which is only supported starting in Mac OS Sonoma: https://bugs.webkit.org/show_bug.cgi?id=183720#c17 . Such detection would most likely be brittle, and possibly inaccurate in those cases.

OrganicChem commented 4 months ago

At your uaparser.dev site, you are detecting arm64 architecture for my M1 Mac. However, using your version 1.0.35 version CDN shows x64. Any explanation for this?

piotrzarzycki21 commented 3 months ago

Looks like issue get back to "normal" and it displays on website as wrong results as it is in reality ;) My Mac is Sonoma 14.5.

Screenshot 2024-07-25 at 16 08 19
OrganicChem commented 3 months ago

Looks like issue get back to "normal" and it displays on website as wrong results as it is in reality ;) My Mac is Sonoma 14.5.

Screenshot 2024-07-25 at 16 08 19

so you are confirming this is an issue?

piotrzarzycki21 commented 3 months ago

Of course @OrganicChem - this issue has been here for more than a year, but I'm not sure if it is resolvable due to some Browser limitations I believe. @faisalman mention this here

mashirozx commented 2 days ago

Why the demo site https://uaparser.dev/ shows the correct OS version, but my code still shows 10.15 even with ua-parser-js@2.0.0 and withClientHints?

Qrivi commented 2 days ago

@mashirozx If I had to guess I'd say your server isn't asking for client hints with the Critical-CH (or Accept-CH on subsequent requests) header so the browser isn't sending them, or your server is not using HTTPS which is required for your browser to send client hint headers.

It's been a while though since I needed to dive into this topic, but I believe those were the 2 main requirements. :)