Workbox will not load

不羁岁月 提交于 2020-01-05 04:11:12

问题


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

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?


回答1:


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. Update the CSP header to allow the Google domain by adding script-src 'self' 'unsafe-eval' https://storage.googleapis.com.

  2. Using Local Workbox Files Instead of CDN



来源:https://stackoverflow.com/questions/53234212/workbox-will-not-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!