-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Issue with "Navigator.platform": Cross-browser API marked deprecated and Chromium-only alternative suggested #14429
Comments
Went down the rabbit hole a bit chasing the origin of this, just out of interest. The origin of the change is in browser-compat-data, where the marking-as-deprecated appears to originate in mdn/browser-compat-data#6567 (comment) by @sideshowbarker, for which the subsequent change was confirmed by @foolip in mdn/browser-compat-data#6612 (comment). |
- Don’t say that navigator.userAgentData.platform is “recommended”; it’s sufficient to just point out that it exists as an alternative. - Since it’s so far only in Blink, say “not yet supported by **most** browsers” rather than “not yet supported by some major browsers. See #14429
For the navigator.platform article, this change replaces the Deprecated_Header macro and its boilerplate text with some more-appropriate alternative pseudo-boilerplate text. See #14429
Thanks much @eemeli for investigating this and pinging me, and thanks @hsivonen for raising this. I have a few questions and comments about this that’ll take me some time to write up, but for now I’ve opened #14452 with changes that I hope might have a chance of resolving it to everybody’s satisfaction. So please take a look at that PR and comment there — either if you have suggestions for specific refinements to it, or if you think it’s not actually at all the right solution to the issue. |
@hsivonen, in case you don’t find #14452 to be a satisfactory resolution to this issue, then some questions:
See #12017 (comment) for some related comments, but to summarize those at point-of-use here, the context of my questions above relates to the following points:
Given all that, it seems like:
That’s why I believe MDN should discourage web developers from writing code that uses |
I guess it’s also worth pointing out here that maybe another thing to consider for this specific case is a spec change. What I mean is, it seems possible, for backward-compat reasons, any UAs currently returning an accurate indication of the platform from That said, if any UA currently returning an accurate indication of the platform from So, if we think that UAs are unlikely to ever actually change their current behavior — that is, if we don’t think that UAs are every going to move to returning the empty string — then perhaps we need to consider changing the spec so that UAs are not allowed to return the empty string for it, and are not “strongly urged to include as little information as possible” from it. But unless/until the spec for this change, then the reasons I’ve outlined here in my other comments are why I believe it’s appropriate and helpful for MDN to discourage web developers from writing code that uses |
Sorry for the verbosity of my comments but I have one last verbose (meta)comment here for now and then I’ll be quiet. To be clear: I actually fully agree that for the specific case of So, somewhat implicit in my #14452 change and my other comments here is a point of view that we could deal with this case and all other cases too by making a global change to using “Discouraged” everywhere we now use “Deprecated”. It’s been understood for quite a while now that the “Deprecated” term has problems in the context of MDN — and at https://github.com/mdn/content/discussions/5549 we have an open/unresolved discussion about the problems, and in https://github.com/mdn/content/discussions/5549#discussioncomment-814689 I’ve proposed we replace it in MDN with “Discouraged”. Anybody reading this might want to also consider weighing in on that discussion. The core problem is, for cases where we want to flag something as being relatively less-reliable for developers to use, the current MDN/BCD flag taxonomy only allows a flag named “Deprecated”. (And all text in the red Deprecated box at the top of the https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform is boilerplate from adding a So, short of making the global shift to “Discouraged” and away from “Deprecated”, we could keep dealing with specific cases like this one by doing what I did in #14452 (replacing the One effect of that is, at https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#browser_compatibility, even with the #14452 change merged, we’ll still have an indicator and generated boilerplate text that says, “Deprecated. Not for use in new websites”. Thus, this issue can’t really be fully resolved without some change to BCD. So a possible additional change we could make is, flip the But I think that’d be the wrong change. I think instead the right BCD change would be to use this issue as an opportunity to go ahead and globally convert the name of the current |
In general, this shouldn't be encouraged, but I can think of an exception: Personally, I can think of one use case where relying on this is probably the least bad option (though I'd be happy to learn about a better option): Checking
My personal educated guess, which shouldn't be taken as a commitment by Mozilla, is that this property is going to continue to distinguish between Apple platforms vs. non-Apple platforms in order to avoid breaking code that decides whether command or control is the keyboard shortcut modifier key. However, personally, I think it's reasonable to expect browsers to consolidate the return values for non-Apple platforms over time. (Within Apple platforms, the return value is already not "accurate" in the sense of iPadOS and macOS on Apple Silicon claiming "MacIntel".)
I think in general, developers shouldn't try to find out the OS, either via I'm a bit shy to suggest that your PR should suggest this use case before seeing comments by others in case I'm just unaware of a better way to decide between command and control. |
Specifically, my educated guess of an end state is that
Source: https://www.chromium.org/updates/ua-reduction/ plus WebKit on iOS and (not tested personally) watchOS returning I haven't done the research of how the empty string ended up in the spec, but it's hard for me to see any vendor having the appetite to pursue that one. |
I did the research and, as a result, made a spec PR to get rid of the empty string. |
Thanks — it’s great to have a specific concrete use case to focus on, and that one’s also the case behind https://css-tricks.com/snippets/javascript/test-mac-pc-javascript/ and some other places where But when you say that for the deciding-on-a-modifier-key case, What is mean is, something like what’s in some of the answers at https://stackoverflow.com/questions/3902635/how-does-one-capture-a-macs-command-key-via-javascript But if that’s not actually a good option for the scenario you in mind — which I can imagine might be if say, the scenario is to give the user guidance up front about exactly which modifier key to press (command or control), based on knowing what platform they’re on — then yeah I can see how there’s a need for On the other hands, if you think doing the |
I agree and I think among the set of people working on developing and maintaining the APIs, there’s agreement about that. However, for the record here, I guess we still need to recognize that web developers are continuing to use So maybe having MDN try to discourage developers from using it is already kind of a lost cause.
OK, then those are further data points to suggest that having MDN try to discourage developers from using |
Notably, this covers the side of showing advice—apparently in a way where writing "control key (or command on Mac)" is considered bad enough that the author wants to show only "control key" or "command key".
This occurred to me. I haven't thought through if this has downsides that would not make this viable advice.
Unfortunately, many of these don't say why they want to know. |
Fixes #14429. For the navigator.platform article, this change does the following: - Drop the Deprecated_Header macro. - Add admonishments that navigator.platform should be avoided in favor of feature detection. - Relegate mention of (equally-bad) navigator.userAgentData.platform to just being a "See also". - Add an example of the single known good case where using navigator.platform isn’t completely bad. Related BCD change: mdn/browser-compat-data#15599
Fixes #14429. For the navigator.platform article, this change does the following: - Drop the Deprecated_Header macro. - Add admonishments that navigator.platform should be avoided in favor of feature detection. - Relegate mention of (equally-bad) navigator.userAgentData.platform to just being a "See also". - Add an example of the single known good case where using navigator.platform isn’t completely bad. Related BCD change: mdn/browser-compat-data#15599 Related spec change: whatwg/html#7762
Fixes #14429. For the navigator.platform article, this change does the following: - Drop the Deprecated_Header macro. - Add admonishments that navigator.platform should be avoided in favor of feature detection. - Relegate mention of (equally-bad) navigator.userAgentData.platform to just being a "See also". - Add an example of the single known good case where using navigator.platform isn’t completely bad. Related BCD change: mdn/browser-compat-data#15599 Related spec change: whatwg/html#7762
…vigator.platform doc and adjust navigator.userAgentData.platform note wording) (#14452) * Adjust wording of note about navigator.userAgentData.platform - Don’t say that navigator.userAgentData.platform is “recommended”; it’s sufficient to just point out that it exists as an alternative. - Since it’s so far only in Blink, say “not yet supported by **most** browsers” rather than “not yet supported by some major browsers. See #14429 * Replace Deprecated_Header in navigator.platform doc For the navigator.platform article, this change replaces the Deprecated_Header macro and its boilerplate text with some more-appropriate alternative pseudo-boilerplate text. See #14429 * Update files/en-us/web/api/navigator/platform/index.md Co-authored-by: wbamberg <[email protected]> * Drop “yet” in text about navigator.userAgentData.platform not being supported/adopted * Un-deprecate navigator.platform; improve advice and example Fixes #14429. For the navigator.platform article, this change does the following: - Drop the Deprecated_Header macro. - Add admonishments that navigator.platform should be avoided in favor of feature detection. - Relegate mention of (equally-bad) navigator.userAgentData.platform to just being a "See also". - Add an example of the single known good case where using navigator.platform isn’t completely bad. Related BCD change: mdn/browser-compat-data#15599 Related spec change: whatwg/html#7762 * Refine explanation of matching on navigator.platform value * Fix markdown formatting of example navigator.platform values * Grammar fix * Update files/en-us/web/api/navigator/platform/index.md Co-authored-by: Jean-Yves Perrier <[email protected]> Co-authored-by: wbamberg <[email protected]> Co-authored-by: Jean-Yves Perrier <[email protected]>
MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
What information was incorrect, unhelpful, or incomplete?
The page claims that
navigator.platform
is deprecated even though it's not marked deprecated in the spec.The page suggests using a Chromium-only alternative even though the page notes that it's neither supported by all major browsers nor accepted by a standards group.
Specific section or headline?
The very top of the document.
What did you expect to see?
Expected the page not to claim deprecation and expected not to suggest using a Chromium-only API instead.
Did you test this? If so, how?
Not applicable.
MDN Content page report details
en-us/web/api/navigator/platform
The text was updated successfully, but these errors were encountered: