Service Worker 陷入无限安装状态 (iOS Safari)
我遇到了一个奇怪的用例,它使我的 PWA 服务工作者进入无限安装状态。
如果我将站点的 SSL 证书从即将过期的证书切换为新证书,站点将检测到新版本,然后该版本将更新到下一个服务工作人员,但在页面重新加载后,它会检测到另一个新版本,一次又一次。我在 Chrome 中没有出现过这种情况,只有 iOS Safari 出现过这种情况。
我唯一能想到为什么会发生这种情况是因为该网站仍然保留着以前的 SSL 证书,这就是 Service Worker 不断更新的原因。
SW 背景:
- 在服务工作人员文件中,我在安装事件中有
self.skipWaiting()
- 对于服务工作人员的客户端,在服务工作人员之后从安装到激活我重新加载页面。
感谢您的帮助!
I have ran into a weird use case that puts my PWA's service worker into an infinite installing state.
If I switch the site's SSL cert from one certificate that's about to expire to a new one, the site will detect a new version, which will then update to the next service worker, but then after the page reloads, it detects another new version, and again and again. I have not had this occur in Chrome, only iOS Safari.
The only thing I can think of why this occurs is because the site is still holding on the previous SSL cert, which is why the service worker keeps updating.
Background on the SW:
- In the service worker file, I have
self.skipWaiting()
in the installing event - For the on client side of the service worker, after the service worker goes from installing to activated I reload the page.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于未来的任何人,我都找到了答案。
发生更新循环的原因是因为在我更新绑定后 Safari 不会发布旧证书。现在 Chrome 确实有类似的行为,它不使用新的证书,但它不会导致无限更新循环。
事实证明,解决方案很简单(适用于 IIS):
您会注意到,即使您实际上尚未更新 PWA 本身,Safari 也会检测到更新。更新后,应加载新证书,然后就可以开始了。
For anyone in the future I have found an answer for this.
The reason the update loop was occurring was because Safari would not release the old cert after I updated the bindings. Now Chrome does have similar behavior with it not using the new cert, but it would not cause an infinite update loop.
Turns out the solution is simple (This is for IIS):
You will notice in Safari a update will be detected even though you haven't actually updated the PWA itself. After the update the new cert should be loaded in and your good to go.