工作箱不会加载 [英] Workbox will not load

查看:49
本文介绍了工作箱不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Workbox 将 PWA 功能添加到我的网站.我正在遵循入门指南,但我'我没有走远.当我在 Chrome 中运行网站时,出现以下错误:

I'm trying to use Workbox to add PWA functionality to my website. I'm following the Get Started guide, but I'm not getting far. When I run the website in Chrome I get the following error:

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'".

根据文档,我在 wwwroot 文件夹中的 service worker 文件中导入 workbox-sw.js,并包含以下行:

Per the docs, I am importing workbox-sw.js in my service worker file that is in my wwwroot folder with the following line:

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

该导入语句中出现拒绝加载..."错误.

The "Refused to load..." error occurs on that import statement.

我怎样才能摆脱这个错误?

How can I get rid of this error?

推荐答案

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

You have a CSP configuration that prevents loading scripts from third-party origins and then you are trying to load a script from Google. You either need to allow the script to load or load the page from your site.

  1. 更新 CSP 标头通过添加 script-src 'self' 'unsafe-eval' https://storage.googleapis.com 来允许 Google 域.

  1. Update the CSP header to allow the Google domain by adding script-src 'self' 'unsafe-eval' https://storage.googleapis.com.

使用本地工作箱文件而不是 CDN

这篇关于工作箱不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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