cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Li, Jonathan" <>
Subject Create hybrid app using iOS cordova with WKWebView
Date Thu, 17 Nov 2016 17:21:52 GMT
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

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>

Do you think the approach works? Or is there other better option?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message