apache / cordova-plugin-device

Apache Cordova Device Plugin
https://cordova.apache.org/
Apache License 2.0
386 stars 428 forks source link

Feature request: get original user agent. #94

Open guylando opened 5 years ago

guylando commented 5 years ago

The browser user agent has a lot of information. If it was overriden by OverrideUserAgent cordova preference then there is no way to get the original user agent from javascript. It would be nice if this plugin would also have a property for the original user agent.

ios possible implementation

https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/Public/CDVUserAgentUtil.m#L37

android possible implementation

String userAgent = System.getProperty( "http.agent" );

https://stackoverflow.com/questions/4103963/is-there-a-way-to-obtain-the-default-user-agent-string-aside-from-webview-getset/10248817#10248817

renatoflorencia commented 4 years ago

I would like this too, I had to use OverrideUserAgent to solve a login problem with google and after that the pieces of my code that verify the device through the plugin do not return the information of the device correctly anymore.

guylando commented 4 years ago

@renatoflorencia hehe, same exact thing here with google login and to solve it I added the ability of getting original user agent in my custom cordova plugin

andreszs commented 3 days ago

That would be great. For the moment, navigator.userAgent retrieves the string, at least in android and browser platforms.

breautek commented 3 days ago

String userAgent = System.getProperty( "http.agent" );

This wouldn't be the original user agent used by the webview. It would be the user agent used by the JVM. So I don't think this is a solution.

Android does have getDefaultUserAgent, this would be a proper solution I think.

I'm not sure if iOS has any equivalent API or even access to the user agent to store a reference.... and that would be a blocker. I believe iOS only has access to the custom user agent which will be nil until set. Ideally features should be implemented for all supported platforms. The https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/Public/CDVUserAgentUtil.m#L37 link is broken, and I don't think CDVUserAgentUtil is something that ever existed.

That would be great. For the moment, navigator.userAgent retrieves the string, at least in android and browser platforms.

The JS navigator.userAgent will return the current (potentially overridden) user agent. Not the original one.