我在电子开发人员控制台中获得了一堆内容安全策略错误,用于添加google字体:
拒绝加载样式表'https://fonts.googleapis.com/css2?family=Inter:wght@300;400&display=swap‘,因为它违反了以下内容安全策略指令:"default-src 'self’‘不安全-内联’数据:“。请注意,'style-src-elem‘没有显式设置,因此“default-src”用作回退。
我用的是电子锻造和TypeScript样板的反应。
发布于 2021-07-25 22:46:14
最简单的方法可能是在模板的标题中设置一个内容-安全-策略元标记,如下所示:
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self';
script-src 'self';
font-src 'self' https://fonts.gstatic.com;
style-src 'self' https://fonts.googleapis.com">
<!-- ...other stuff... -->
</head>关于如何使用这些工具的指南如下:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#multiple_content_security_policies
我现在正处于电子的第一个小时,暂时没有反应,这就是我如何绕过它,我认为这就是你应该怎么做的。
https://stackoverflow.com/questions/68445115
复制相似问题