oracle / cordova-plugin-wkwebview-file-xhr

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

cordova ios 6.1.0 wkwebview all xhr POST requests are converting as blob request. #74

Closed knkavya closed 3 years ago

knkavya commented 3 years ago

Hi,

I have migrated the Cordova app from UIWebview to WKWebview.I have a native scanner screen that is invoked from the webpage and to invoke this I am using the "cordova-plugin-wkwebview-file-xhr" and "cordova-plugin-wkwebviewxhrfix" plugins. Which is working fine by launching a scanner. But on the same page, the other ajax post calls are getting failed and they are converted as blob requests.

I tried removing the "cordova-plugin-wkwebview-file-xhr" plugin post that all the post ajax call works perfectly. But Scanner will not be invoked without xhr plugin.

All the calls are getting invoked using xhr-polyfill.js file where the post calls are failing. Can someone please help me to fix this issue?

XHR plugin issue
knkavya commented 3 years ago

Hi,

Can someone please help me in solving the above issue? Is there any alternate plugin that is available to serve the same purpose as "cordova-plugin-wkwebview-file-xhr"?

manish2788 commented 3 years ago

@knkavya Any specific reason for using "cordova-plugin-wkwebviewxhrfix" plugin along with this plugin?

knkavya commented 3 years ago

@manish2788 Yes. To provide local file access in our app I am using "cordova-plugin-wkwebviewxhrfix" plugin.

manish2788 commented 3 years ago

@knkavya Does that plugin do anything different from our plugin "cordova-plugin-wkwebviewxhr". Reason I am asking is to ensure the other plugin is not causing any conflict.

knkavya commented 3 years ago

@manish2788 Yes. I am having a json file with json data which is kept in some server location and I am reading it as XMLHttpRequest(). Only by using "cordova-plugin-wkwebview-file-xhr" plugin, I was not able to read the json file. After installing "cordova-plugin-wkwebviewxhrfix" plugin along with this plugin I was able to read the json data properly in my app.

But this plugin is used only to read that json file and nowhere else it is used. In all the places only the "cordova-plugin-wkwebview-file-xhr" plugin is used. I have tried by removing "cordova-plugin-wkwebviewxhrfix" plugin the issue is same. Whenever the POST-call enters into xhr-polyfill.js send request my ajax post calls are getting failed and they are converted as blob request.

newuser44 commented 3 years ago

I'm having the same problem that my requests are showing up as blobs. I don't know how big of deal that is except makes it harder to debug requests.
I was pointed to this plugin to help with ios 14 and cross sites cookies being saved correctly.
Also confused on what this plugin is actually doing. Seems like XMLHttpRequest is a javascript funtion.

Probably wonder off and not sure if this has to do with the blob problem but my login call and cookies I can see. Seems like the next two or three apis also have cookie and work correctly but then everything breaks down. Hard to debug.

knkavya commented 3 years ago

Is anyone having an update on the fix for this issue or any alternate solution for this?

newuser44 commented 3 years ago

Is anyone having an update on the fix for this issue or any alternate solution for this?

I got things working this way.
https://forum.ionicframework.com/t/ionic-3-wkwebview-ios-14-itp-best-options/201628/2?u=helpmelearn

I removed this plugin and other cookie plugins to fix this ios 14 issue.

I'm on ionic 3.20 with ionic-ios 5.1.1.

knkavya commented 3 years ago

Is anyone having an update on the fix for this issue or any alternate solution for this?

I got things working this way. https://forum.ionicframework.com/t/ionic-3-wkwebview-ios-14-itp-best-options/201628/2?u=helpmelearn

I removed this plugin and other cookie plugins to fix this ios 14 issue.

I'm on ionic 3.20 with ionic-ios 5.1.1.

I am using cordova 6.1.0 now if I downgrade the version to 5.1.1 which still having some of the references to UIWebview, So not sure whether Apple will approve the app or not.

Cordova version 5.1.1 for WKWebview is internally having "cordova-plugin-wkwebview-file-xhr" plugin installed with file xhr-polyfill.js and where the issue still exists.

knkavya commented 3 years ago

Hi Team,

Any update on this issue fix?

manish2788 commented 3 years ago

@knkavya This plugin is working as expected. It resolves the null origin issue of ios app by handling all remote requests at the native layer where the origin header will be excluded. The XHR request polyfill of this plugin is creating the blob request to overcome the issue. You have mentioned that your ajax call are failing but I don't see any issue with ajax call failing even if it is a blob request.

knkavya commented 3 years ago

@manish2788 Thank you for the update. I am not getting any response for the post request which are converted as blob requests. These requests were working fine in UIWebview where post requests and responses were fine. Not sure is there anything that needs to be modified in the ajax request or response handling for the WKWebview update. Can you please provide more clarification on this?

manish2788 commented 3 years ago

@knkavya We cannot comment upon you are not getting the response but I would recommend you to create a basic starter cordova app, try adding an ajax request and observe the behaviour on same.

knkavya commented 3 years ago

@manish2788 Problem occurs only for the post request.

Below are the details of my request

Whenever my POST call enters performNativeXHR method inside CDVWKWebViewFileXhr below are the request data

requestId : b684.0000000008-0.2cdd62334e5df8 callbackFunction : nativeXHRResponse urlString : https://store.*****.grp/shop/getAccountBalance method : post

request :

<NSMutableURLRequest: 0x6000000052d0> { URL: https://store.*****.grp/shop/getAccountBalance } { body = "c3RvcmVJZD0xOTc1MyZhZGRySWQ9MDAwMDEyMDA2OQ=="; callback = nativeXHRResponse; headers = { accept = "application/json, text/javascript, /; q=0.01"; "content-type" = "application/x-www-form-urlencoded; charset=UTF-8"; "x-requested-with" = XMLHttpRequest; }; id = "b684.0000000008-0.2cdd62334e5df8"; method = POST; url = "https://store.*****.grp/shop/getAccountBalance"; }

When the request enters a method NSURLSessionDataTask task = [self.urlSession dataTaskWithRequest:request completionHandler:^(NSData _Nullable data, NSURLResponse _Nullable response, NSError _Nullable error)

Gives me security issue for the request as

Task .<6> finished with error [-1202] Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “store...” which could put your confidential information at risk."

and it is converting the request as a blob request.

Whereas for other calls I am not getting any security issue like this.

I have tried adding transport security exceptions to ignore invalid certificates, but the issue is still the same.

manish2788 commented 3 years ago

@knkavya Issue doesn't seems to be related with plugin. Closing the same as conversion to blob request is expected behaviour of this plugin.