如何在清单 v3 中设置正确的 Chrome 扩展 content_security_policy 正则表达式

发布于 2025-01-20 12:07:27 字数 714 浏览 1 评论 0原文

我正在使用清单版本2,一切都很好,但是不幸的是,版本2不再是2023年后。因此,我决定迁移到版本3。 我正在定义content_security_policy如下:

"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; 
  object-src 'self'"

现在我试图将其设置为下面

"content_security_policy":{
  "extension_pages" : "script-src 'self' https://ssl.google-analytics.com; 
  object-src 'self'"
} 

,但我得到了此错误:

Refused to load the script 'https://ssl.google-analytics.com/ga.js' because it 
violates the following Content Security Policy directive: "script-src 'self'". Note 
that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

如何解决此问题?

I was using manifest version 2 and everything was fine, But unfortunately, version 2 is no longer after 2023. So I've decided to migrate to the version3.
I was defining content_security_policy as below:

"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; 
  object-src 'self'"

and now I'm trying to set it as below

"content_security_policy":{
  "extension_pages" : "script-src 'self' https://ssl.google-analytics.com; 
  object-src 'self'"
} 

But I got this error:

Refused to load the script 'https://ssl.google-analytics.com/ga.js' because it 
violates the following Content Security Policy directive: "script-src 'self'". Note 
that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

How can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文