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 5.1.1 cannot load resources due to file:// protocol #76

Closed csantanu closed 3 years ago

csantanu commented 3 years ago

Due to UIWebview to WKWebview migration, we have used Corodova iOS 5.1.1 and this plugin@2.1.4

All the CORS issue is resolved and build is successful. However, in device it's failing to load eBook cover images & epub files after successfully downloading from remote (it's an ebook application). Safari web inspector shows 'cannot load resource. Operation not permitted' error. Console is showing downloaded files as "file://". As per my understanding this plugin resolves the 'file' load issue but it is not working. Are we missing any thing specific? Any help will be highly appreciated.

BrianCortes commented 3 years ago

hi @csantanu I have had the same problem 😭 I am using Cordova iOS 6.1.0 and I resolved the problem with this steps: according to cordova you need to add a new custom schema to load local files:

Add those preferences in your config.xml

<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />

Note: maybe you need to add this plugin cordova-plugin-wkwebview-engine, because your version is not the last

Then you should run cordova prepare or cordova compile to get the new schema in your system also you need to Content-Security-Policy for the new scheme in this case app this is a example

 <meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' 'unsafe-eval' filesystem: app: gap://ready *; style-src 'unsafe-inline' blob: *; media-src *; img-src 'self' data: blob: filesystem: app: *">

And there is a function to convert a file url to a custom scheme url:

 window.WkWebView.convertFilePath(nativeUrl);

I hope this information help in your issue

csantanu commented 3 years ago

Hello @BrianCortes Thanks for the inputs. I have meanwhile upgraded my project to Cordova iOS 6.1.1. This does away with the cordova-plugin-wkwebview-engine as it is already built into the core.

Based on few other posts in stackexchange / GitHub, I have not used any schema but added this plugin (V3.0 meant for iOS >6.x) & cordova-plugin-wkwebviewxhrfix. The app builds and executes without any issue in the device. But the file loading is still an issue.

window.WkWebView.convertFilePath(nativeUrl) is generating run-time error as it is not able to reference WkWebView object as this is part of cordova-plugin-wkwebview-engine.

I will try with setting the schema & updated Content-Security-Policy and let you know if these measures fixed the issue.

csantanu commented 3 years ago

@BrianCortes No luck. Added security-policy & schema. Same issue, the images / files showed correctly downloaded in console but all with file:// tags and so when trying to open, they throw error.

manish2788 commented 3 years ago

@csantanu Any reason for using cordova-plugin-wkwebviewxhrfix along with this plugin? Can you please summarise the issue you are facing when using cordova-plugin-wkwebviewxhr plugin (v3.0) alone. We don't provide cordova-plugin-wkwebviewxhrfix so can't comment if usage of that plugin is causing any issue.

csantanu commented 3 years ago

@manish2788 without using this plugin (AraHovakimyan/cordova-plugin-wkwebviewxhrfix) along with Oracle's plugin, the app stops during loading itself. Web console starts showing CORS errors and none of the remote resources are loaded. As soon as the additional fix plugin is added, all resources gets downloaded and loaded correctly. However, what I understood from this plugin's readme, that it is suppose to resolve the file:// issue but that's not happening.

manish2788 commented 3 years ago

@csantanu This plugin resolves the issue as mentioned in description I am not sure what is the issue which you are facing at your end. Can you share a sample cordova app which demonstrates the issue which you are reporting.

manish2788 commented 3 years ago

Closing the issue due to lack of response.

signalpoint commented 3 years ago

Thank you @BrianCortes , your info above helped me resolve a similar issue here.