DOMException when registering service worker insid

2019-02-22 21:38发布

问题:

I'm trying to register a service worker in an https iframe inside an http (unsecured) site. Until lately, my code ran without any issues. From the last chrome update (44) this code fails inside the iframe:

navigator.serviceWorker.register('./service-worker.js');

I get this error in console: Uncaught (in promise) DOMException: Only secure origins are allowed

Was there any change that now prevents secured iframes from registering service workers if they are running in an unsecured parent?

回答1:

It appears that this did change recently. It also appears that the current behaviour will now be maintained - see this discussion at the service worker spec repository. Both of those discussions cite this specification as the basis for the policy.