0

I have an Angular application that uses @angular/service-worker to register a service worker in the user's browser.

If the user has a certificate error in their browser (e.g. if the CN doesn't match), the service worker registration fails with the following error:

Service worker registration failed with: DOMException: Failed to register a ServiceWorker for scope ('[...]') with script ('[...]'): An SSL certificate error occurred when fetching the script.

This breaks some follow-up logic in my app, so it would be best if I could just not attempt service worker registration if I knew beforehand that this issue will occurr.

However, window.isSecureContext returns true, so I can't make the service worker registration depend on that.

Is there a way of detecting if the page is actually secure, and not just 'fake secure' with a red padlock in the URL bar?

In Firefox is there are no such issues, but in Chrome and Edge there seem to be different rules for window.isSecureContext and service worker registration.

I am aware that a proper SSL setup is the 'correct' solution, but in my situation, that unfortunately isn't possible.

DaBittna
  • 1
  • 1
  • it is probably already answered [here](https://stackoverflow.com/questions/38728176/can-you-use-a-service-worker-with-a-self-signed-certificate) – Andrei Sep 26 '22 at 15:39

0 Answers0