Deprecated Javascript OS detection techniques

2019-07-11 14:35发布

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.

2条回答
ら.Afraid
2楼-- · 2019-07-11 14:57

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

查看更多
地球回转人心会变
3楼-- · 2019-07-11 15:11

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.

查看更多
登录 后发表回答