我尝试将sw.js文件放在子目录中,而不是根目录中。但随后我收到一个错误,指出无法安装service-worker。
这个文件真的有必要放在根目录中吗?或者我只是遗漏了什么?
JS-代码:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/js/pwa/sw.js', { scope: '/js/pwa' }).then(function(reg) {
console.log('Successfully registered. Scope is ' + reg.scope);
}).catch(function(error) {
console.log('Registering failed ' + error);
});
} else {
console.log('Service worker can not be registered on this device');
}发布于 2019-10-01 22:11:43
如果我做了同样的事情,我会得到以下错误
Registering failed SecurityError: Failed to register a ServiceWorker: The path of the provided scope ('/js/pwa') is not under the max scope allowed ('/js/pwa/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.下面的部分看起来很奇怪。
{ scope: '/js/pwa' }请按以下步骤操作
{ scope: '/js/pwa/' }https://stackoverflow.com/questions/58185483
复制相似问题