cordova-plugin-device
cordova-plugin-device copied to clipboard
Feature request: get original user agent.
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
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.
@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
That would be great. For the moment, navigator.userAgent
retrieves the string, at least in android and browser platforms.
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.