loading polymer app into an iOS WKWebView fails

255 views
Skip to first unread message

Jim Trainor

unread,
May 2, 2016, 12:17:50 PM5/2/16
to Polymer
Polymer applications fail to load in an iOS WKWebView, as supported by Cordova. The root cause of the problem is that WKWebView does not permit loading of content via file:.  Cordova's support for WKWebView bypasses this restriction by implementing a in-app web server to host the static content. Polymer fails because the polymer code tries to load a local, static, html file, using a file:// url via an XHR request. The file:// XHR request is rejected by WKWebView.

This has turned into a blocking issue for publishing Polymer applications, using Cordova, on iOS.

Does this sound familiar to anybody?

Is there anyway to cleanly define the URL where Polymer loads elements (or whatever is loaded via the file:// XHR)?





Karl Tiedt

unread,
May 2, 2016, 12:34:34 PM5/2/16
to Jim Trainor, Polymer
Nothing in polymer appears to reference file:// anything... this sounds like it may be a Cordova issue?

-Karl Tiedt

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/72dda4a2-5447-4dec-a4e7-b075a02927ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Trainor

unread,
May 2, 2016, 3:10:36 PM5/2/16
to Polymer
 am about to revisit this in depth… but… the last time I dug in there was definitely an XHR load of an html file originating from polymer (from the web component.min.js, actually, as I recall, which I am classifying generically as “polymer”).

As I recall the XHR request was loading html web components from its host (I think it was loading the entire vulcanized html file). If that host url happens to be file:// then that is what it used for the XHR request.  The problem is… WKWebView rejects that access… so no-go for the Polymer app.

If the page is loaded via an ordinary http request then all is well. The exact same code loading via an Android WebView is fine also.  The problem is limited to security restrictions in WKWebView. See the bug link that I posted for more info.

Eric Bidelman

unread,
May 2, 2016, 3:22:14 PM5/2/16
to Jim Trainor, Polymer
On IOS (a polyfilled browser), the web components polyfill loads html imports using XHR. This means that from a webview, they're loaded from file:///, which is typically blocked by browsers/environments for security reasons.

Unsure if there's an equivalent in ios, but in android webview, you can override this setting:

The other option is to vulcanize your entire app (vulcanize index.html -o index.v.html) which removes all import requests.

Jim Trainor

unread,
May 2, 2016, 4:00:41 PM5/2/16
to Polymer
I am not aware of any override on WKWebView that permits file:// access.

I’m the second person to have posted this as a bug on the  Apache Cordova bug tracker. It is not hard to file other reports of people stumbling over the lack of file:// support in WkWebView.  The embedded web server approach seems to be the usual solution.  But that doesn’t capture the file:// XHR requests.

… so… hmm…. head scratch… seems to be a blocker at the moment.

Eric Bidelman

unread,
May 2, 2016, 5:47:54 PM5/2/16
to Jim Trainor, Polymer
Or the other suggestion:
> The other option is to vulcanize your entire app (vulcanize index.html -o index.v.html) which removes all import requests.

jim.t...@wellbalancedmeal.com

unread,
May 3, 2016, 6:45:09 AM5/3/16
to Polymer, jim.train...@gmail.com
Thanks for reiterating. I will try that suggestion.
Reply all
Reply to author
Forward
0 new messages