You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置manifest.json消除嵌入式Google Maps iframe的CSP告警

解决方案

你需要在manifest.json的content_security_policy字段中添加frame-src指令,允许浏览器加载谷歌地图的iframe资源,根据你使用的Manifest版本不同,配置方式如下:

如果你使用Manifest V2

修改配置为:

"permissions": [
  "https://www.google.com/maps/*"
],
"content_security_policy": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://*.google.com https://*.gstatic.com; frame-src https://www.google.com/maps/ https://*.googleusercontent.com; connect-src 'self' https://*.google.com"

如果你使用Manifest V3

Manifest V3的CSP配置为对象格式,修改为:

"permissions": [
  "https://www.google.com/maps/*"
],
"content_security_policy": {
  "extension_pages": "script-src 'self'; object-src 'none'; frame-src https://www.google.com/maps/ https://*.googleusercontent.com; img-src 'self' data: https://*.google.com https://*.gstatic.com; style-src 'self' 'unsafe-inline'"
}

配置说明

  • 核心生效规则是frame-src,它是CSP中专门用来限制当前页面可以嵌入哪些来源iframe的指令,添加谷歌地图相关的域名后就能消除警告
  • 上述配置没有放开多余的权限,不会引入额外的安全风险
  • 你原有组件代码不需要做任何修改,更新manifest后重新加载扩展即可生效

内容的提问来源于stack exchange,提问作者Lazy Loading

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.15 05:15:00