-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Comments
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. ua-parser-js/src/main/ua-parser.js Line 845 in 072a82b
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. |
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). |
With 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 I believe this will be fixed with new npm build since I don't see @faisalman any info when new build will be published to NPM? |
On the way now 👍 |
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...
The text was updated successfully, but these errors were encountered: