0
votes

I have a domain at https://example.co.uk, and one at https:// chat.example.co.uk, both using service workers in production. When developing on localhost, I can use a service worker on the https://example.co.uk domain (on localhost:1337), but not when using the chat subdomain (on chat.localhost:1337), or any other subdomains.

This is not an issue on the live version, but it makes development quite difficult when working on the service workers' code.

Am I missing something important, or is there something I can do to allow the service worker to register anyway?

I tried turning the #allow-insecure-localhost Chrome flag on, but I don't think that was the problem.

1

1 Answers

0
votes

As you've observed, only http://localhost is whitelisted by Chrome for features that require secure contexts, not any subdomains of localhost—which I don't think are a thing without jumping through some hoops in your local domain resolution setup?

To facilitate local testing, I'd recommend instructing your web server to listen to requests on localhost on two different ports, e.g. 1337 and 1338. That would probably be the easiest way to simulate the two different origins that you have in production, with their isolated security contexts.

It obviously might require be some additional effort to refactor your configuration so that instead of communicating with a subdomain in your dev environment, you communicate with a the same localhost domain, but a different port.