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

Un-deprecate navigator.platform (was: Replace Deprecated_Header in navigator.platform doc and adjust navigator.userAgentData.platform note wording) #14452

Merged
merged 9 commits into from
Mar 31, 2022
6 changes: 4 additions & 2 deletions files/en-us/web/api/navigator/platform/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ tags:
- platform
browser-compat: api.Navigator.platform
---
{{ APIRef("HTML DOM") }} {{Deprecated_Header}}
{{ APIRef("HTML DOM") }}

> **Note:** The recommended alternative to this property is {{domxref("NavigatorUAData.platform", "navigator.userAgentData.platform")}}. However, {{domxref("NavigatorUAData.platform", "navigator.userAgentData.platform")}} is not yet supported by some major browsers, and the specification which defines it has not yet been adopted by any standards group (specifically, it is not part of any specification published by the W3C or WHATWG).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sideshowbarker @teoli2003 Does it make sense to remove the info/links to NavigatorUAData.platform?

I understand the desire to point to feature detection, and the reasoning why navigator.platform shouldn't be deprecated.

But despite the spec change to navigator.platform my take is that you would be much better off using NavigatorUAData.platform. The user hints are more fully designed and specified - and while they aren't on all platforms, neither is the value of navigator.platform reliable on any platform.

Copy link
Collaborator Author

@sideshowbarker sideshowbarker Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sideshowbarker @teoli2003 Does it make sense to remove the info/links to NavigatorUAData.platform?

I think it doesn’t make sense to remove it completely — which is why I moved it to being a See Also — but I think given the current state of things, it doesn’t make sense to give it as much prominence as it had.

I think giving it that amount of prominence made sense when we had navigator.platform marked as Deprecated — because in that case, we actually had people asking, OK, if this is deprecated, then what’s the alternative?

But as the fact that #14429 was raised kind of shows, we create a different problem when when we give this particular alternative the kind of prominence we were giving it — especially if we say it’s recommended.

But despite the spec change to navigator.platform my take is that you would be much better off using NavigatorUAData.platform. The user hints are more fully designed and specified

One thing we need to recognize is the people who work on non-Blink/Chrome browsers projects are not super happy if MDN promotes the use of some feature to developers when the current reality of that feature is that in practice it’s a Blink-only feature — even when that feature has a well-intentioned actively-maintained spec.

But it doesn’t matter how good the spec is if other browser projects aren’t implementing and it and aren’t even showing interest. And in the specific case of Client Hints, there was even at one time some discussion about having https://mozilla.github.io/standards-positions/ list is a Harmful.

It’s now marked “non-harmful” there but anyway we need to recognize that the Mozilla engineering team does not seem to be any interest in ever implementing Client Hints.

And while the Safari/WebKit team also doesn’t seem opposed to ever implementing Client Hints (see https://lists.webkit.org/pipermail/webkit-dev/2020-May/thread.html#31195), working on actually implementing doesn’t seem to be any significant priority for them — to the point that they haven’t even bothered to list it at https://webkit.org/status/.

my take is that you would be much better off using NavigatorUAData.platform

After looking through a lot of navigator.platform usages in Stack Overflow questions and answers in GitHub code, I can say that in nearly all cases where people are using navigator.platform in code, they are not using it for good reasons — and the kinds of things they are doing are things that we actually want to discourage developers from doing.

The same goes for ways in which somebody might use NavigatorUAData.platform — the underlying problem with both properties is that it’s fundamentally a bad idea to try to be finding out information about the user’s environment rather than only relying on feature detection.

I am aware of only one single case in which it makes sense to try and get information about the user’s platform — and that’s the deciding-on-which-modifier-key-to-advise-to-the-user case which I added an example for in the patch here.

Other than that one case, I’m not aware of even a single other best-practice case of something to do in code based on finding out information about the user’s platform — whether by using navigator.platform or with Client Hints.

and while they aren't on all platforms, neither is the value of navigator.platform reliable on any platform.

The key big differences are that navigator.platform is actually implemented in every browser engine (even if its reliability may vary), and navigator.platform is part of a standard that’s gone through the process of getting agreement and endorsements among multiple browser projects.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation. I can get on board with it being a "see also".

> **Warning:** Use of this feature is discouraged. It may have known problems, or it may be a feature that works as expected now, but for which in the future behavior may change in a way that will break code that relies on it continuing to work in the same way it does now. Or it may be a feature which a specification has marked as deprecated or obsolete. Avoid using it, and update existing code if possible; see the [compatibility table](#browser_compatibility) to guide your decision.
sideshowbarker marked this conversation as resolved.
Show resolved Hide resolved

> **Note:** An alternative to this property is {{domxref("NavigatorUAData.platform", "navigator.userAgentData.platform")}}. However, {{domxref("NavigatorUAData.platform", "navigator.userAgentData.platform")}} is not yet supported by most browsers, and the specification which defines it has not yet been adopted by any standards group (specifically, it is not part of any specification published by the W3C or WHATWG).
sideshowbarker marked this conversation as resolved.
Show resolved Hide resolved

Returns a string representing the platform of the browser.
The specification allows browsers to always return the empty string, so don't rely on this property to get a reliable answer.
Expand Down