You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/12/08 12:30:28 UTC

[GitHub] [cordova-ios] breautek commented on issue #1038: WkWebView adding to local files does not allow the files to be found/viewed.

breautek commented on issue #1038:
URL: https://github.com/apache/cordova-ios/issues/1038#issuecomment-740591506


   The reason why you see this is because WKWebView enforces CORS on all network traffic in the browser that is cross-origin. WKWebView will also treat all requests as cross-origin when running from the `file://` protocol. Generally speaking, you should be using the `cordova-plugin-file` APIs to read local files, however it's understandable that some frameworks such as Angular (and I assume  SAPUI5) uses XHR to read files. Unfortunately there is no API to change the CORS restrictions but I'll provide two options that are available.
   
   ### Option 1
   
   Option 1 is to migrate to schemes. This will be the most ideal option for the long term, however there is one caveat. When you use schemes, the origin of your cordova web app will change, thus the location of the web storage will also change and thus become **inaccessible**. If there is important data stored in cookies, local storage, indexed db, etc, that can't be easily recreated, then Option 2 will be a good short term solution. Alternatively, there is data migration plugins available that is easily adaptable to migrate the web storage data to the new storage containers.
   
   ### Option 2
   
   If Option 1 is out of the picture because you have important data stored and you cannot migrate it for whatever reason, then using [Oracle's plugin](https://github.com/oracle/cordova-plugin-wkwebview-file-xhr) will redirect all your `XMLHttpRequest` calls to a natve layer to bypass those CORS restrictions. Do note this applies only to local `file://` urls. I think this plugin is similar to the one you have already installed, but I've personally communicated with Oracle team and I know lots of other people who had success with their plugin.
   
   Because we use GitHub for tracking issues only, I'll be closing this issue. If you require further assistance, I'd invite you to our [Slack Community](http://slack.cordova.io/).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org