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/07/17 13:01:01 UTC

[GitHub] [cordova-plugin-wkwebview-engine] breautek commented on issue #166: Not able to see the first page of my app.

breautek commented on issue #166:
URL: https://github.com/apache/cordova-plugin-wkwebview-engine/issues/166#issuecomment-660093534


   To answer this question:
   
   You are likely running into a CORS problem when requesting local files. You'll need a wkwebview file xhr plugin.
   
   Alternatively, you can upgrade to `cordova-ios@6`, remove `cordova-plugin-wkwebview` and use schemes. This will however cause you to lose web storage data. The data will still be on the device, but it will not be accessible, because of the origin change.
   
   > Additionally, maybe someone read this... and want to answer this question: why we must use the referred "fix" plugin in addition to the "cordova-plugin-wkwebview-engine" plugin? I mean, the "fix" plugin allows us to run apps made by AngularJS but also VueJS, for example.
   
   ### Little background
   
   The reason why the wkwebview xhr fix is necessary for apps that uses certain frameworks like Angular is because those frameworks makes heavy usage of `XMLHttpRequest` to local urls (`file://`...), which is illegal in the webview because of CORS. That fix plugin works by overwriting the webviews version of XMLHttpRequest with a native version that doesn't enforce CORS on local urls.
   
   I don't know if there was ever a community decision but personally I have a few problems with approach:
   
   1. Overwriting native behaviour is generally frowned upon by Apple, especially when it comes to security constructs. While I never heard of an app being rejected because of the wkwebview xhr fix, I would be concerned that it is possible.
   
   2. Generally if you need to read files from the local file system, you won't go through a network stack, you'd simply read the files directly using the file APIs. Angular framework obviously makes certain assumptions, and one of those assumptions is that it is running on a website, powered by a webserver. Which is a false assumption with Cordova apps.
   
   ### Cordova's approach
   
   Cordova has chosen a different approach to tackle this problem, which is available in cordova-ios@6. If you're using schemes, you don't need the wkwebview xhr fix plugin. Because schemes have an origin attached which eliminates several CORS-related issues, not just the xhr issue.
   
   This still does pose a different problem however, for existing apps. Because changing from `file://` to a custom URL scheme changes the origin, you'll lose acccess to any data stored in web storage (local storage, indexedDB, cookies, etc). Because of this, cordova chose to keep the `file://` protocol as a default in cordova-ios@6, but it does break the wkwebview file xhr plugin.
   
   side note: the plugin you linked to isn't being maintained. There is a plugin maintained by Oracle that I would probably suggest https://github.com/oracle/cordova-plugin-wkwebview-file-xhr to use instead, and they are working on upgrading their plugin to support cordova-ios@6.


----------------------------------------------------------------
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