cordova-plugin-device icon indicating copy to clipboard operation
cordova-plugin-device copied to clipboard

Feature request: get original user agent.

Open guylando opened this issue 5 years ago • 4 comments

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

guylando avatar Mar 11 '19 22:03 guylando

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 avatar Jul 15 '19 18:07 renatoflorencia

@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

guylando avatar Jul 15 '19 23:07 guylando

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

andreszs avatar Jun 28 '24 12:06 andreszs

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.

breautek avatar Jun 28 '24 12:06 breautek