Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is window.navigator.userAgent really going to be deprecated?

Tags:

javascript

I just read on MDN about window.navigator.userAgent:

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.

I am not finding any other significant reference on the web confirming this statement. User agent information are widely used by many companies for various reasons (analytics, bug fixes in specific browser ...). While I understand that one should use feature detection over ua sniffing it just seems incredible that this information would go away.

Is it really going away or is it just a Mozilla thing?

If so, is there a replacement for it?

like image 903
Arnaud Leyder Avatar asked Dec 10 '15 10:12

Arnaud Leyder


2 Answers

The deprecation notice seems to be gone now. It was removed yesterday, over a year after this question was first asked, with the following comment:

rm deprecation marker. This is not removed from the living spec and no deprecation either. Most use cases are discouraged for quality reasons, but that's something else.

The WHATWG Living standard hasn't deprecated this property, so that confirms that the property isn't going away. Sure, it's a crapshoot and easily spoofed, but "not recommended for use" is not the same as "deprecated". As you note, too many authors and organizations depend on this property for it to be simply specced out of existence and removed from implementations.

Perhaps confusion over the meaning of the word "deprecated" is what resulted in the deprecation notice in the first place. The article itself is still incorrectly tagged "Deprecated", by the way.

Note that Mozilla is not responsible for contributions to the MDN docs. The community is. And as with any other community-curated, unofficial knowledge base (including this very site), don't treat its information as gospel, always cross-reference, etc (as you have done here).

like image 175
BoltClock Avatar answered Sep 21 '22 21:09

BoltClock


Use feature detection. If you need to use feature X, test to see if X is available.

like image 30
db48x Avatar answered Sep 24 '22 21:09

db48x