工作箱无法加载

时间:2018-11-09 22:44:20

标签: service-worker progressive-web-apps workbox

我正在尝试使用Workbox将PWA功能添加到我的网站。我正在按照Get Started指南进行操作,但距离不远。当我在Chrome中运行网站时,出现以下错误:

Refused to load the script 'https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".

根据文档,我将wwwbox文件夹中的service worker文件中的workbox-sw.js导入以下行:

importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');

在该导入语句上发生“拒绝加载...”错误。

如何摆脱这个错误?

1 个答案:

答案 0 :(得分:1)

您有一个CSP配置,可以防止从第三方来源加载脚本,然后您正尝试从Google加载脚本。您要么需要允许脚本从您的网站加载页面,要么加载页面。

  1. Update the CSP header通过添加script-src 'self' 'unsafe-eval' https://storage.googleapis.com来允许Google域。

  2. Using Local Workbox Files Instead of CDN