15

I was wondering why javascript os detection techniques like navigator.userAgent, navigator.appName, navigator.appVersion and navigator.platform are in process of being dropped from web standards.

https://developer.mozilla.org/en-US/docs/Web/API/Navigator

If you visit every of those navigator props, you can see

Deprecated

This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

So I would like to know

  1. Why they're removing this
  2. Will they introduce a new way for OS detection
  3. Can I use these techniques even if they're deprecated.

Probably there is a lot of cases where we need to know OS version.

15
  • 2
    while this is a good question, this probably isn't the right place to ask it. Aside from not having a problem to be solved, it's also opinionated, as no single person other than those responsible for drafting the web standards can tell you their reasoning. It also is on the edge of being a rant in disguise. Commented Jul 21, 2016 at 14:13
  • 2
    @JKirchartz: The only real (and not obsolete) use-case I've ever seen for platform detection is when offering downloadable software: With detection, you can default to the platform (say, Linux) the user is viewing your page with (while still letting them navigate to other platforms [say, Windows]). Commented Jul 21, 2016 at 14:17
  • 1
    @T.J.Crowder: And for that, you could just as easily do it server-side, which I'm guess will still have userAgent. Commented Jul 21, 2016 at 14:22
  • 1
    I think we're all on the same page, here. Commented Jul 21, 2016 at 14:29
  • 2
    I'm voting to close this question as off-topic because the premise is that OS detection aspects of navigator are deprecated, but neither the spec nor MDN indicates that the primary OS-related property, navigator.platform, is in fact being deprecated. Commented Jul 21, 2016 at 14:47

3 Answers 3

2

It was incorrectly or accidentally marked as deprecated on MDN. They quickly corrected the page once they saw the problem, but since it had been a definitive source, references to it being deprecated still exist here and there.

Here's the conversation where it was fixed: https://groups.google.com/forum/#!topic/mozilla.dev.mdc/tIx2iiH2u3o

Sign up to request clarification or add additional context in comments.

1 Comment

To update for 2023, all of the keys OP mentions (besides userAgent) are now in fact deprecated, according to MDN: developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
-2

You can use:

navigator.userAgentData.platform

1 Comment

Not supported in most browsers (Firefox for example). See developer.mozilla.org/en-US/docs/Web/API/Navigator/….
-5

I think the general thinking is that it's becoming unnecessary. Theoretically at least, there shouldn't be any functionality that works differently in any browser vs any other browser--at least not for JavaScript.

What you usually browser sniff for are features, and there are plenty of ways to find most of that stuff out without having to infer anything from the nightmare that is userAgent.

So it may be deprecated, or it may not. But it's a good idea to not have to sniff the browser. That stuff can get real complicated real fast. Even if it does become deprecated though, it'll probably stick around for a few decades so that half the web that still relies on it doesn't crash and burn.

2 Comments

I want to display an icon in Apple platforms and another one in Android platforms. I think it's a legit use case.
Disagree - another use case is for keyboard shortcuts: on a KeyboardEvent, metaKey flag is Mac's Command key but Windows' WinKey. Normally you'd want Ctrl + S and Cmd + S to both save, on Windows and Mac respectively

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.