收到错误内容安全策略错误:拒绝创建工作人员
Posted
技术标签:
【中文标题】收到错误内容安全策略错误:拒绝创建工作人员【英文标题】:getting error content-security-policy error: refused to create worker 【发布时间】:2021-08-06 05:35:45 【问题描述】:在我的 Angular 项目中。我收到下面提到的错误
refused to create a worker from 'blob:http://localhost:4200/d8633b89-9f70-4fd6-b08a-e369ccd34273' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' https://cdn.jsdelivr.net/npm/pdfjs-dist@2.5.207/es5/build/pdf.worker.js". Note that 'worker-src' was not explicitly set, so 'script-src' is used as a fallback.
我知道其相关的内容安全政策。我已经设置了 CSP。在这里
default-src 'self';
script-src 'self' 'unsafe-eval' https://cdn.jsdelivr.net/npm/pdfjs-dist@2.5.207/es5/build/pdf.worker.js;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
img-src 'self' data: https://*.amazonaws.com;
media-src 'self' data: https://*.amazonaws.com;
connect-src 'self' http://localhost:* ws://localhost:*;
font-src 'self' https://fonts.gstatic.com https://fonts.googleapis.com data:;
childSrc blob
worker-src blob:
但我仍然遇到错误。
【问题讨论】:
【参考方案1】:我认为缺少分号来分隔font-src
、child-src
(我想childSrc
不正确)和worker-src
default-src 'self';
script-src 'self' 'unsafe-eval' https://cdn.jsdelivr.net/npm/pdfjs-dist@2.5.207/es5/build/pdf.worker.js;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
img-src 'self' data: https://*.amazonaws.com;
media-src 'self' data: https://*.amazonaws.com;
connect-src 'self' http://localhost:* ws://localhost:*;
font-src 'self' https://fonts.gstatic.com https://fonts.googleapis.com data:;
child-src blob:;
worker-src blob:;
【讨论】:
以上是关于收到错误内容安全策略错误:拒绝创建工作人员的主要内容,如果未能解决你的问题,请参考以下文章