In general, you should not care what Operating System visitors are using to visit your website. If you attempt to be clever, you will often get it wrong and cause problems that are an annoyance for users and a hassle for me to debug.
So avoid trying to be nosy/clever if at all possible.
That being said, some folks want to know for whatever reason; I’m an engineer, not a cop.
The typical path to get this information from Windows-based browsers is to look at the dreaded User-Agent string, a wretched hive of lies, scum, and villainy.
However, this approach falls down with Windows 11, which reports itself as Windows NT 10.0
(almost certainly for compatibility reasons); in general, browsers are moving toward freezing the User-Agent string to limit passive fingerprinting.
If you want to be able to distinguish between Windows 10 and Windows 11, starting around October 2021 in Microsoft Edge 95 (and v95 of most Chromium browsers), the Sec-Ch-UA-Platform-Version
Client Hint is the way to go.
Available for request in v95, this value will indicate the UniversalApiContract
“API Level” of the Windows platform. The mapping of values to version is
Windows Version | Sec-CH-UA-Platform-Version |
Windows 7 | 8 | 8.1 | 0.0.0 |
Windows 10 1507 | 1.0.0 |
Windows 10 1511 | 2.0.0 |
Windows 10 1607 | 3.0.0 |
Windows 10 1703 | 4.0.0 |
Windows 10 1709 | 5.0.0 |
Windows 10 1803 | 6.0.0 |
Windows 10 1809 | 7.0.0 |
Windows 10 1903 | 1909 | 8.0.0 |
Windows 10 2004 | 20H2 | 21H1 | 10.0.0 |
Windows 11 Previews | 13.0.0 | 14.0.0 |
Windows 11 Release | 15.0.0 |
You can request this Client Hint from JavaScript thusly:
navigator.userAgentData.getHighEntropyValues(['platformVersion'])
.then(uapv => { console.log(uapv.platformVersion); });
Or you can request it be sent to your server on subsequent requests using
Response.AddHeader("Accept-CH"
, "Sec-CH-UA-Platform-Version");
Response.AddHeader("Accept-CH-Lifetime", "86400");
As you may have noticed, the 0.0.0
value is shared across all pre-Windows 10 versions of Windows, so you’ll need to continue to use the User-Agent string to distinguish between Windows 7, 8.0, and 8.1 platforms.
As far as I know, Firefox does not plan to implement this Client Hint.
Bonus: Platform Bitness
Distributors of native applications often would like to know the bitness and architecure of the client platform. The sec-ch-ua-bitness
and sec-ch-ua-arch hints are useful for this purpose.
Unfortunately, there’s a bug in Chromium whereby ARM64 devices like the Surface Pro X will return x86
as the architecture.
The Edge-proprietary window.external.getHostEnvironmentValue()
API returns the truth {"os-architecture":"ARM64"}
but this API is non-standard and you should not use it.
-Eric
PS: Native client apps should generally not check the registry key directly, instead it should query the appropriate “Is this API level supported” API. HKLM\SOFTWARE\Microsoft\WindowsRuntime\WellKnownContracts\Windows.Foundation.UniversalApiContract
Impatient optimist. Dad. Author/speaker. Created Fiddler & SlickRun. PM @ MSFT '01-'12, and '18-, presently working on Microsoft Edge. My words are my own. View more posts