gpt4 book ai didi

service-worker - navigator.serviceWorker 从未准备好

转载 作者:行者123 更新时间:2023-12-02 03:43:30 28 4
gpt4 key购买 nike

我成功注册了一个 service worker,但是代码

navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
// Do we already have a push message subscription?
....

挂起 - 永远不会调用该函数。为什么?

最佳答案

问题是 service-worker.js 文件存储在 assets 中。子目录。

不要那样做:将 service-worker.js 存储在 root of your app 中(或更高)。这样你的应用就可以访问 service-worker。

HTML5Rocks article ——

One subtlety with the register method is the location of the service worker file. You'll notice in this case that the service worker file is at the root of the domain. This means that the service worker's scope will be the entire origin. In other words, this service worker will receive fetch events for everything on this domain. If we register the service worker file at /example/sw.js, then the service worker would only see fetch events for pages whose URL starts with /example/ (i.e. /example/page1/, /example/page2/).



已添加

一个新问题是,如果页面被硬重新加载,serviceworker 永远不会准备好。随后的软页面重新加载工作正常。谷歌自己的示例代码失败。 See the Chrome bug report.

错误修复包含在 Chrome 44 中。

关于service-worker - navigator.serviceWorker 从未准备好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874068/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com