Polymer + Cordova: Can’t access device images

Polymer’s <app-location> wipes out URL parameters. Capture Cordova’s cdvToken beforehand.

Ronny Roeller
NEXT Engineering
2 min readAug 1, 2017

--

We package our Polymer application with Cordova. We thereby use Cordova’s local webserver plugin to access the device images in the WKWebView (all the details).

Lately, the device images were suddenly no longer visible because the webview refused access to the images. After some debugging, we found out that the cdvToken was no longer added to the index.html when loading the application. What was going on?

Normally, Cordova’s local webserver plugin adds the cdvToken, which authorizes access to the device images. Debugging the code in XCode showed that the local webserver still added the cdvToken but it somehow got lost while starting the application.

Finally, we identified <app-location> as the one to blame! During a recent refactoring, the element containing <app-location> was no longer delayed attached but got imitatively active. Now, <app-location> directly nuked all URL parameters — before we could capture the cdvToken.

From there, working around the issue was trivial (whereby ready waits until the URL parameters are captured):

<template is="dom-if" if="[[ready]]">
<app-location route="{{route}}"></app-location>
</template>

Stopping <app-location> from blindly removing all URL parameters would be the proper solution. You can follow this ticket for progress.

Happy coding!

Want to learn more about Polymer? Have a look to all our Medium posts on Polymer.

--

--

Ronny Roeller
NEXT Engineering

CTO at nextapp.co # Product discovery platform for high performing teams that bring their customers into every decision