更新时间:2022-02-01 02:56:04
我不确定,但是您可以尝试像这样注册 worker,以便我们可以获得有关进度的更多信息并正确设置路径:
I am not sure, but can you try to register the worker like this, so we can have additional information about the progress and set the path correctly:
...
navigator.serviceWorker
.register("service-worker.js", {
scope: './' }).then(function (registration) {
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
console.log('installing');
} else if (registration.waiting) {
serviceWorker = registration.waiting;
console.log('waiting');
} else if (registration.active) {
serviceWorker = registration.active;
console.log('active');
}
if (serviceWorker) {
// logState(serviceWorker.state);
serviceWorker.addEventListener('statechange', function (e) {
// logState(e.target.state);
});
}
}).catch({…})
你也可以展示一下
service-worker.js
service-worker.js
文件?