5

I am trying to get started on debugging my Polymer application. I have hand crafted it by copying what I think the PolymerCLI Polymer init does.

I am not sure what is loading service worker. The default one for development just does a console.info() call saying its been disabled for development.

When I use Polymer serve to serve my application on localhost: 8080, I get the console.info message, despite there being nowhere where I actually load the file service-worker.js . Because the application is much more complex (and I am trying to use http/2) I have my own node based server as well. When I run that and then fetch my application in the browser, service-worker.js does not get loaded and run.

What is Polymer serve doing to enable it?

Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
akc42
  • 4,893
  • 5
  • 41
  • 60
  • Which `polymer init` template are you using? E.g. `polymer init application`, `polymer init app-drawer-template`, etc. – Kayce Basques Jun 09 '16 at 17:16
  • I hand crafted the app since it existed before polymer cli was created. I created a standard application in an alternative directory and copied the appropriate files (service-worker.js, sw-precache-config.js) and used the rest of the files as guides to edit what I already had. – akc42 Jun 09 '16 at 21:21

1 Answers1

7

It could be that a different application which used the same source (e.g. localhost:8080) registered and installed a service worker.

Open up the Application panel in Chrome Canary to inspect / delete the service worker.

enter image description here

If you can't access Chrome Canary, open chrome://serviceworker-internals, find the scope that matches your app, and click Unregister. There's also an option at the top of serviceworker-internals which lets you open a DevTools window and pause JS on the SW. Enable that option and you'll be able to see which SW is running.

Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
  • This is probably it, although I am not sure how to check because I haven't got canary installed (I am running Debian). I created a dummy app with polymer init just to see what it would do. I also created a copy of to google shop application to look at that. One of those might have done that, but why does console log respond what is in my `/service-worker.js` – akc42 Jun 09 '16 at 21:15
  • @akc42 check out the workflow at the bottom of my edited answer – Kayce Basques Jun 09 '16 at 23:30
  • Thanks. I "think" I get it now. It appears that the code in the dummy app registered the url `/service-worker.js` when it was located at localhost:8080. This service worker code is identical to the code in my app because I just copied it so it is impossible to say which version is being used. The only puzzle I have now is that I thought service workers are https only, and this was is being activated on localhost http connection. – akc42 Jun 10 '16 at 06:49
  • @akc42 you are mostly correct that service workers must run over HTTPS, but `localhost` is one of the few exceptions. The [spec](https://www.w3.org/TR/service-workers/#security-considerations) says "Devtools can loosen the [security] restriction for development (file://, localhost, etc.)". – Kayce Basques Jun 10 '16 at 14:41