【问题标题】:How to get Service Worker working on Chrome Lighthouse?如何让 Service Worker 在 Chrome Lighthouse 上工作?
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • 这里一样,除了我,它被称为“清除存储”。 This GitHub issue comment 告诉我在哪里做。 ?
  • 如果您仍然想知道选项在哪里,窗口右侧有一个设置按钮,它将为您展开。还是行不通?在隐身模式下执行此操作,它应该这样做。
【解决方案2】:

取消选中“清除存储”似乎也可以工作

【讨论】:

    猜你喜欢
    • 2018-11-25
    • 2020-11-16
    • 2020-07-07
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2019-05-14
    相关资源
    最近更新 更多