oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
138 stars 120 forks source link

UserAgent is "YOUR_APP/1 CFNetwork/1220.1 Darwin/20.3.0" #80

Closed jperdereau closed 3 years ago

jperdereau commented 3 years ago

xCode Version 12.4 (12D4e) Simulator on iPad 8th gen iOS 14.4 cordova: "10.0.0" cordova-ios: "6.1.1"

Using XHR or window.fetch on https://www.whatsmyua.info/api/v1/ua you get a UA like "YOUR_APP/1 CFNetwork/1220.1 Darwin/20.3.0"

Using the Cordova config to override and append is not working anymore https://cordova.apache.org/docs/en/10.x/config_ref/index.html

OverrideUserAgent(string) AppendUserAgent(string)

manish2788 commented 3 years ago

@jperdereau Are you facing this issue while using this plugin in your app or without the plugin as well?

jperdereau commented 3 years ago

I do not have the issue without the plugin.

flav142 commented 3 years ago

Same for me. UA is wrong on an iOS Cordova app using this plugin. I'm using an iPhone X on iOS 14.4 with cordova-ios 6.2.0.

This will break my analytics in order to known with browsers / operating system are visiting my web app.

manish2788 commented 3 years ago

@jperdereau Can you share a sample app to demonstrate the issue.

jperdereau commented 3 years ago

Here https://github.com/jperdereau/sample_issue_cordova-plugin-wkwebview-file-xhr

Here the Readme to install https://github.com/jperdereau/sample_issue_cordova-plugin-wkwebview-file-xhr/blob/master/Readme.md

The first commit is without the plugin Screen Shot 2021-03-18 at 19 48 36

The second commit just add the plugin Screen Shot 2021-03-18 at 19 51 57

jperdereau commented 3 years ago

Any news on your side?

manish2788 commented 3 years ago

Hi @jperdereau , We will be sharing the update on this issue by this week end.

manish2788 commented 3 years ago

@jperdereau Following response is being fetched from the server. At the plugin end we are not processing the response and modifying it. What I understand is that you must be creating this response at server end and passing it back to client. You need to provide us the client property which is being used by your server to generate "ua" object having 'rawUa' key. Otherwise I don't see any override from plugin to modify the incoming response.

meta: {name: "useragent", repo: "https://github.com/3rd-Eden/useragent", version: "2.2.1"}

os: {string: Object, family: "Other", major: "0", minor: "0", patch: "0"}

ua: {rawUa: "HelloCordova/1.0.0 CFNetwork/1206 Darwin/19.6.0", family: "CFNetwork", major: "0", minor: "0", patch: "0", …}
jperdereau commented 3 years ago

Hello,

Not sure I understand.

The sample app is full client, it just fetch from https://www.whatsmyua.info/api/v1/ua https://github.com/jperdereau/sample_issue_cordova-plugin-wkwebview-file-xhr/blob/master/www/js/index.js#L44

https://www.whatsmyua.info/ is not mine, just a website to know your UA.

manish2788 commented 3 years ago

@jperdereau Since this is a 3rd part api to check UA we cannot comment how exactly they are fetching the UA information from app. Have you tried yourself in your app to fetch the user agent instead of using a 3rd part website?

jperdereau commented 3 years ago

Indeed I have the issue on analytics and another microservice that we are calling from the client app.

manish2788 commented 3 years ago

Indeed I have the issue on analytics and another microservice that we are calling from the client app.

@jperdereau My query was, have you tried fetching the user agent without using mentioned 3rd party website. If yes can you let me know how you achieved that?

manish2788 commented 3 years ago

Closing the issue due to inactivity.

jperdereau commented 3 years ago

Well the issue is on a fetch, I need to fetch or xhr something, I can create a small node server on the side that show the UA but the issue will be the same. Checking on the app before sending as no point because the change is done by the native request too me.

lilmnm-kamikaze- commented 3 years ago

This issue still needs to be open. my server requires the use of the user agent set in the config.xml this plugin overrides it

aefw commented 3 years ago

This plugin is great but this issue not solved until today I got useragent like @jperdereau not full useragent this plugin not updated, please @oracle fixed this issue Thanks

cemelmaci commented 2 years ago

please check reqContext.requestHeaders with <preference name="NativeXHRLogging" value="full" />. if reqContext.requestHeaders['User-Agent'] is not there, add it to xhr-polyfill.js line 604 like reqContext.requestHeaders['User-Agent'] = navigator.userAgent; before creating reqPayload.