【发布时间】:2021-12-12 20:24:17
【问题描述】:
我正在尝试在 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
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);
})
}
在清单中:
start_url: "/",
scope: "/",
我也试过了:
"../", "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
但是,我也尝试使用 https 在远程服务器中运行该应用程序,但遇到了同样的错误。
任何帮助都会很好。
【问题讨论】:
-
看起来 Chrome v 95 在 Service Workers 灯塔测试方面存在一些问题,请参阅 github.com/GoogleChrome/lighthouse/issues/13236
-
谢谢,我发现如果我取消选中灯塔选项中的清除缓存选项,它就会开始工作。
标签: lighthouse