如何让 Service Worker 在 Chrome Lighthouse 上工作?

How to get Service Worker working on Chrome Lighthouse?

我正在尝试在 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 的远程服务器中的应用程序,但我遇到了同样的错误。

任何帮助都会很好。

如果我取消选中灯塔选项中的清除缓存选项,它就会开始工作。

编辑:正如 Sean McCarthy 在下面提到的,正确的名称是“清除存储”

取消选中“清除存储”似乎也有效