简体   繁体   English

即使注册成功,服务工作人员也显示为已删除

[英]service worker showing as deleted even though registration was successful

I can't seem to figure out any reason why a service worker would be deleted with the code that I have that registers or actually is the service worker. 我似乎无法弄清楚为什么服务工作者会被我注册的代码或实际上是服务工作者的代码删除。

But in this site, it shows up as deleted in the Service Workers section of the chrome dev tools (image below). 但在此站点中,它在chrome dev工具的Service Workers部分中显示为已删除 (下图)。

Yet it is also registering properly as logged in the console (same image below). 然而,它也在登录控制台时正确注册(下图中相同)。

在此输入图像描述

Here is the service worker registration code: 这是服务工作者注册码:

if('serviceWorker' in navigator){

    navigator.serviceWorker.register('/earnie.min.js', { scope: '/'}).then(function(registration){
        console.log('Registration successful, scope is:', registration.scope);
}).catch(function(error){
        console.log('Service worker registration failed, error:', error);
    });
}

Here is the service worker code: 这是服务工作者代码:

var cachename="e2",cachelist=";;.;/;./;/privacyPolicy.html;/css/main.css;/css/normalize.css;".split(";");

self.addEventListener("install",function(a){
    a.waitUntil(caches.open(cachename).then(function(a){
        return a.addAll(cachelist)
    }))
});
self.addEventListener("fetch",function(a){
    a.respondWith(caches.match(a.request).then(function(b){
        return b?b:fetch(a.request.clone(), { credentials: 'include', redirect: 'follow' })
    }))
});

What is causing it to be deleted and not registering? 是什么导致它被删除而没有注册?

Registration succeeded, but installation actually fails. 注册成功,但安装实际上失败了。 Your waitUntil() promise is not resolving, which causes InstallEvent event to fail, thus deleting the ServiceWorker. 您的waitUntil()承诺未解析,这会导致InstallEvent事件失败,从而删除ServiceWorker。 cachelist probably returns invalid/empty values when you run split(';') 运行split(';')时, cachelist可能会返回无效/空值

I recommend ensuring that cachelist is an array with valid URI values, then you can debug within the install event** 我建议确保cachelist是一个具有有效URI值的数组,然后你可以在install事件中调试**

self.addEventListener("install", event => {
  event.waitUntil(
    caches.open(cachename)
    .then(cache => cache.addAll(cachelist))
    .catch(error => console.error('💩', error))
  )
})

**You'll most likely need "Preserve log" console option enabled in Chrome Dev Tools to see the console error. **您最有可能在Chrome开发工具中启用“保留日志”控制台选项以查看控制台错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重新加载页面后 Service Worker 显示为已删除 - Service Worker showing as deleted after reloading the page 服务人员注册问题 - Service Worker Registration issue 服务人员注册未返回 - service worker registration not returning Service Worker 注册失败 - Service Worker Registration Failed 即使我有一个 Service Worker 并且我的 PWA 工作正常,也没有检测到匹配的 Service Worker - No matching service worker detected even though I have a service worker and my PWA is working fine 即使在服务中有数据,对象在html中仍显示为未定义 - Object showing as undefined in html even though it has data in the service 即使在注册时指定根范围后,Service Worker 也会被删除并且不会收到推送事件 - Service Worker gets deleted and does not receive push event even after specifying root scope while registering Service Worker:事件处理程序已经完成(即使从事件处理程序同步调用) - Service Worker: The event handler is already finished (even though called synchronously from the event handler) 即使成功响应,firebase数据库也不会更新 - firebase database not updating, even though successful response 即使请求成功,JSON ParseError也是如此 - JSON ParseError even though request was successful
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM