我的注册服务工作者有问题。
当我在localhost
中运行我的服务工作者来测试他时,我看到了这个错误:
dont Activated: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
这是我的服务工作者注册代码 - app.js文件中的所有代码:
if('serviceWorker' in navigator) {
navigator
.serviceWorker
.register('/service-worker.js').then(registration => {
console.log('Service worker has been Activted :' , registration);
}).catch(err => {
console.log('dont Activated:' , err )
})
} else {
console.log('Servise workers not actived')
}
我的service-worker.js文件在我的根文件夹中!
我仔细地链接了所有文件。
您需要在https上运行您的网络服务器。如果您不使用https,服务人员可能会很麻烦。