An alternative to JavaScript's navigator.platform

In the past, you could do the following to get the user's platform:

javascript
let platform = navigator.platform
// MacIntel

This expression is deprecated and will be disabled in future navigator versions. As is stated in here, Chromium team plans to reduce the granularity of available information in the User-Agent.

Why? Because the User-Agent exposes a lot of the user's information that can be used for fingerprinting.

The alternative is to use the User-Agent Client Hints API. For example, navigator.platform could be:

javascript
let platform = navigator.userAgentData.platform

I suspect that the users will be more in control of the navigator's retrieved info. 👌

As most of the browsers haven't yet the new userAgentData API, it's advised to check if it's accessible, because it can lead to errors in production:

javascript
let platform = navigator?.userAgentData?.platform || navigator?.platform || 'unknown'

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.