我正在尝试在 Chrome Lighthouse 上审核我的应用程序,但我无法让 Service Worker 工作。它已注册并运行,没有错误,但是当我尝试运行 Lighthouse 时,它被卡住并控制台记录以下错误:
Service worker not registered DOMException: Failed to register a ServiceWorker for scope ('https://www.localhost.com/') with script ('https://www.localhost.com/sw.js'): Operation has been aborted
Run Code Online (Sandbox Code Playgroud)
SW 的调用方式为:
if('serviceWorker' in navigator){
let sw = 'sw.js';
navigator.serviceWorker.register(sw, {scope: "/"})
.then(function(){
console.log('Service worker registered.');
})
.catch(function(e){
console.log('Service worker not registered ', e);
})
}
Run Code Online (Sandbox Code Playgroud)
在清单中:
start_url: "/",
scope: "/",
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
“../”、“https://www.localhost.com/”、“./”、
我正在使用以下标志运行 chrome:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://www.localhost.com
Run Code Online (Sandbox Code Playgroud)
但是,我还尝试使用 https 在远程服务器中运行该应用程序,但出现了相同的错误。
你能帮忙的话,我会很高兴。
如果我取消选中灯塔选项中的清除缓存选项,它就会开始工作。
编辑:正如 Sean McCarthy 在下面提到的,正确的名称是“清除存储”
| 归档时间: |
|
| 查看次数: |
1733 次 |
| 最近记录: |