Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 11 will not detected #665

Closed
saschahaendle opened this issue Jul 13, 2023 · 4 comments
Closed

Windows 11 will not detected #665

saschahaendle opened this issue Jul 13, 2023 · 4 comments

Comments

@saschahaendle
Copy link

Hello,

i use us-parser-js in a project. When i open my site on Windows 11, the os version always shows 10. If i open the ua-parser-js demo site in the same browser, it shows the right os version.

I call the function with
`let ua = new UAParser();

// get browser data from user-agent only :
let browser = ua.getOS();
console.log('Using User-Agent: ', browser);

// alternatively :
ua.getOS().withClientHints().then(function (browser) {
console.log('Using Client-Hints: ', browser);
}); `

I don't found anything in the documentation how i call the function right. Can anybody help me?

thanks a lot...

@samueleastdev
Copy link

samueleastdev commented Jul 28, 2023

Hey @saschahaendle,

I was just about to ask the same question.

The issue is that the userAgent string returns "Windows 10" even if it's on a Windows 11 computer, so there is no reliable way to do this using the userAgent string.

I looked into whether Windows 11 had any new APIs that could be used to differentiate between Windows 10 and Windows 11, but no luck.

Then, we found this in the Microsoft documentation: https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11

navigator.userAgentData.getHighEntropyValues(["platformVersion"])
 .then(ua => {
   if (navigator.userAgentData.platform === "Windows") {
     const majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
     if (majorPlatformVersion >= 13) {
       console.log("Windows 11 or later");
      }
      else if (majorPlatformVersion > 0) {
        console.log("Windows 10");
      }
      else {
        console.log("Before Windows 10");
      }
   }
   else {
     console.log("Not running on Windows");
   }
 });

From my testing so far, this does indeed work correctly for me and should be integrated into this npm package if its reliable maybe you could test aswell I only have Windows 11 right now.

@faisalman I see you already use this here.

IData.prototype.withClientHints = function () {

There is doc on how it is implemented here.

https://faisalman.github.io/ua-parser-js-docs/v2/api/ua-parser-js/idata/with-client-hints.html

const ua = new UAParser();

ua.getBrowser().withClientHints().then(function (browser) {
    console.log('Using Client-Hints: ', browser);
});

You need the latest code not the npm version. Trying to test it my Windows 11 computer now.

@samueleastdev
Copy link

This is definitely known, but I'm including it here for additional information. It appears that most user agent detection will eventually need to transition to the Client Hints API. Consequently, this package will require a major update for browser detection due to the User-Agent Reduction for privacy, which is being introduced by most modern browsers.

For more details, you can refer to the documentation: https://martechseries.com/mts-insights/guest-authors/the-impact-of-user-agent-reduction-and-client-hints-on-privacy/

In a nutshell, browsers will be providing less information via the User-Agent String. Instead of the specific version (e.g., Chrome 104.11.5.9), the reduced UA string will only return major versions (e.g., Chrome 104.0.0.0).

@coderpradp
Copy link

coderpradp commented Aug 14, 2023

With v2.0.0-alpha.2 you can use following example to get correct Windows version.

const UAParser = require('ua-parser-js')

UAParser().withClientHints().then(result => console.log(result))

This will use new Client Hints API in supported browser to get correct OS version.

Quirk: I had to use require to import browser library. ES6 import will load ESM library which defines const window = undefined. So, it does not utilize Client Hints API.

I believe this will be fixed with new npm build since I don't see const window = undefined with new ESM builds.

@faisalman any info when new build will be published to NPM?

@faisalman
Copy link
Owner

faisalman commented Aug 17, 2023

@faisalman any info when new build will be published to NPM?

On the way now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants