Hi, This is unnecessarily complex for cordova users since it is not the web paradigm, and is not portable across platforms.
If you want to experiment using your proposed method: You can fork the cordova-plugin-wkwebview-engine [1], and modify the source to suit your purpose. Make sure to rename the plugin. Either that, create your own plugin to depend on the cordova-plugin-wkwebview-engine, and inherit from the wkwebview-engine class to override certain methods. Ionic has some ideas on how to bridge the xhr limitation, but unfortunately that pull request has been withdrawn for now [2]. You can take a look at their implementation. [1] https://github.com/apache/cordova-plugin-wkwebview-engine [2] https://github.com/apache/cordova-plugin-wkwebview-engine/pull/15 On Thu, Nov 17, 2016 at 9:21 AM, Li, Jonathan <jonathan...@sap.com> wrote: > Hi, > Recently we start to investigate the possibility to adopt WKWebView for > building ios cordova hybrid apps. Currently those apps are built with > UIWebView on ios cordova library. > > In our application, the main html content is loaded from remote web server > at runtime, and local cordova js resource are then injected into html page > to leverage the device native functions, such as camera, calendar, etc. As > the html page is loaded from remote server using https connection, the > wkwebview will not allow the local web resource (for example, cordova.js) > to be injected into the html page by local file url (file:// url). We also > tried to use the cordova localhost webserver plugin to inject the local web > resource into the html page, but that does not work either as localhost web > server plugin only supports http connection, and wkwebview does not allow > to inject http content into the https html page. In addition, as > https://localhost: is a different domain from the remote web page, so xhr > request from https://localhost: will not be able to receive wkwebview’s > didReceiveAuthenticationChallenge callback method to handle the > challenge. Those limitations also apply even if injecting cordova web > resource to a new iframe on the https html page. > > So, in order to solve the issue, I wonder whether it is possible to have > an option in cordova to allow loading the js resource as javascript context > so instead of loading the js file as url as shown below > <script type=”text/javascript” src=”pluginscript.js”></script> > the javascript content will be loaded directly into the script element > <script type=”text/javascript” script> > …raw plugin script content > </script> > > In this way, all the cordova script and remote https content can live in a > single domain to avoid the cross domain limiation. > > The initial loading of codova.js and other preload plugin js files can be > injected using wkwebview userContentController at > WKUserScriptInjectionTimeAtDocumentEnd. For the on-demand loading of > plugin js files, the cordova.js can let the require method to send a > cordova bridge call and then use wkwebview’s evaluateJavaScript method to > load those javascitp content in <script> element. > > Do you think the approach works? Or is there other better option? > > Thanks > Jonathan > > >