Testing service workers on custom local domain with self signed certificate

When playing around with service workers in order to make a site a progressive web app I had to test it on my local dev environment. As service workers need to run on https and I use a self-signed certificate for development. This gave me the following error in the console in Chrome

ServiceWorker registration failed: DOMException: Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script.

The solution is to tell Chrome to accept the certificate even though it is insecure from Chrome’s point of view. Just paste this in your terminal (Mac only) and you should be good to go – just don’t go browsing elsewhere too much:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/foo --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://your-local-domain.test

One response to “Testing service workers on custom local domain with self signed certificate

  1. After one has tested the web app in Chrome for macOS, how does one test it in Safari in order to verify that it uses no features that Chrome implements and Safari does not?

Leave a Reply

Your email address will not be published. Required fields are marked *