Currently,
On Windows-11 devices I'm getting navigator.userAgent value as Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.77 which is same as Windows-10.
To distinguish between Windows-10 vs Windows-11, I have used User-Agent Client Hints
navigator.userAgentData.getHighEntropyValues(['platformVersion']).then(function(uapv){
console.log(uapv.platformVersion);
var winVer = Number(uapv.platformVersion.split('.')[0]);
if(winVer>10){
console.log("It's Win11")
}else{
console.log("It's Not Win11");
}
});
But,
User-Agent Client Hints are only supported in Chrome/Edge/Opera but not in Firefox.
So, is there a technique/library available to detect Windows-11 in Firefox ?
Yes, Microsoft themselves have given this solution using javascript.
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"); }
});
for reference https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
EDIT: I haven't tested to see if it works on Firefox yet. But from my own experience it works on Brave and Chrome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With