Skip to content

Instantly share code, notes, and snippets.

@marceltn
Last active May 25, 2018 15:46
Show Gist options
  • Save marceltn/a877443995343ecd106a80f717a32ff1 to your computer and use it in GitHub Desktop.
Save marceltn/a877443995343ecd106a80f717a32ff1 to your computer and use it in GitHub Desktop.
Debug Service Worker
https://www.chromium.org/blink/serviceworker/service-worker-faq
# Link to service workers in Chrome
chrome://inspect/#service-workers
chrome://serviceworker-internals
Q: When I have Developer Tools open, requests go straight to the network; the Service Worker does not get a fetch event.
A: On the Developer Tools' Network tab, if Disable cache is checked, requests will go to the network instead of the Service Worker. Uncheck that.
Q: I get an error message about "Only secure origins are allowed". Why?
A: Service workers are only available to "secure origins" (HTTPS sites, basically) in line with a policy to prefer secure origins for powerful new features. However http://localhost is also considered a secure origin, so if you can, developing on localhost is an easy way to avoid this error.
You can also use the --unsafely-treat-insecure-origin-as-secure command-line flag to explicitly list a HTTP Origin. For example:
$ ./chrome --unsafely-treat-insecure-origin-as-secure=http://your.insecure.site:8080
(Prior to Chrome 62, you must also include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the unsafely-treat-insecure-origin-as-secure flag to work.)
If you want to test on https://localhost with a self-signed certificate, do:
$ ./chrome --allow-insecure-localhost https://localhost
You might also find the --ignore-certificate-errors flag useful.
Q: I made a change to my service worker. How do I reload?
A: From Developer Tools > Application > Service Workers, check "Update on reload" and reload the page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment