无法注册服务人员

问题描述 投票:0回答:1

我的注册服务工作者有问题。

当我在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文件在我的根文件夹中!

我仔细地链接了所有文件。

pwa
1个回答
0
投票

您需要在https上运行您的网络服务器。如果您不使用https,服务人员可能会很麻烦。

© www.soinside.com 2019 - 2024. All rights reserved.