在 https iframe 中注册服务工作者时出现 DOMException

DOMException when registering service worker inside an https iframe

我正在尝试在 http(不安全)站点内的 https iframe 中注册服务工作者。 直到最近,我的代码 运行 没有任何问题。从上次 chrome 更新 (44) 开始,此代码在 iframe 中失败:

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

我在控制台中收到此错误: Uncaught (in promise) DOMException: Only secure origins are allowed

如果安全 iframe 运行 在不安全的父级中,是否有任何更改可以阻止安全 iframe 注册服务工作者?

看来 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 作为政策的基础。