注册 ServiceWorker 失败:ServiceWorker 无法启动 [英] Failed to register a ServiceWorker: ServiceWorker cannot be started

查看:217
本文介绍了注册 ServiceWorker 失败:ServiceWorker 无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Service Worker 项目一切正常,但突然我看到以下错误:

Everything was working fine with my Service Worker project, but suddenly I am seeing the following error:

Uncaught (in promise) DOMException: Failed to register a ServiceWorker: ServiceWorker cannot be started

尽管我在一个名为 sw.js 的文件中注册了软件,但它被报告为 index.html:1.

This is being reported as on index.html:1 although I am registering the SW in a file called sw.js.

我在 Google 上找不到任何内容 - 有关导致此错误发生的原因的任何指导?

I couldn't find anything on Google - any guidance on what causes this error to occur?

推荐答案

原来这只是说明 Service Worker 代码本身存在 JS 错误,导致注册无法完成.

So it turns out this just indicates there is a JS error in the Service Worker code itself, so the registration couldn't complete.

加载 chrome://serviceworker-internals/并选中打开 DevTools 窗口并在 Service Worker 启动时暂停 JavaScript 执行以进行调试."

Load chrome://serviceworker-internals/ and check 'Open DevTools window and pause JavaScript execution on Service Worker startup for debugging.'

然后当你刷新页面时会弹出检查器,让你看到 Service Worker 中的错误.

The inspector will then pop up when you refresh the page, allowing you to see the error in the Service Worker.

这篇关于注册 ServiceWorker 失败:ServiceWorker 无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆