ipfs/service-worker-gateway

User-friendly error on redundant service worker registration

lidel opened this issue · 1 comments

Problem

What happens when service worker gateway is used to load website which has own service worker code?

IIUC if the scope of the new service worker is the same as or a subset of the scope of the existing service worker, the new service worker will not be able to take control until the existing service worker is unregistered or its scope is changed.

AFAIK attempting to register a service worker with a conflicting scope won't result in an error, but it won't replace the existing service worker either, creating situation which is hell to debug and reason about.

Solution

  • navigator.serviceWorker registration involves sending HTTP request for worker code with `Service-Worker: script" header
  • helia-service-worker-gateway should detect such requests and return HTTP 501 Not Implemented with human-readable error, or at least link to this issue.
  • this way, registration of worker on top of existing worker won't be possible, and end user won't ever end up in broken state, and many correctly designed websites and tools should work fine (if worker was only an optional optimization for caching/offline mode).

Do we have an example website in this state? The only one I know of is https://helia-service-worker-gateway.on.fleek.co/ right now which you can test at https://helia--service--worker--gateway-on-fleek-co.ipfs.sw.sgtpooki.com

image