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

Chrome扩展中Firebase弹窗认证遇CSP错误,添加合规URL仍未解决

解决Chrome扩展Manifest V3中Firebase Auth弹窗登录的CSP及显示问题

针对你遇到的弹窗无法显示、CSP错误问题,给你几个关键修复点:

1. 补充CSP的frame-src规则

Firebase的Google/GitHub弹窗登录本质是加载第三方iframe,你当前的CSP仅配置了connect-src,缺少frame-src来允许加载这些登录页面。需在extension_pages的CSP中添加对应规则:

"content_security_policy": {
  "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; connect-src 'self' https://*.firebaseapp.com https://*.googleapis.com wss://*.firebaseio.com https://identitytoolkit.googleapis.com https://accounts.google.com https://*.google.com; frame-src https://accounts.google.com https://github.com/login/oauth/authorize"
}

2. 添加identity权限

Chrome扩展中使用第三方OAuth登录必须声明identity权限,否则无法正确处理弹窗的权限与重定向逻辑。在permissions数组中加入:

"permissions": [
  "tabs",
  "activeTab",
  "offscreen",
  "identity"
]

3. 配置Firebase授权域

登录Firebase控制台,在Authentication > 设置 > 授权域中添加你的扩展ID对应地址:chrome-extension://<你的扩展ID>,确保扩展页面被Firebase认可为合法登录发起源。

4. 调整登录代码执行环境

Manifest V3的service worker是无DOM环境,不能直接调用signInWithPopup。请将登录逻辑放在action的popup页面或你配置的newtab页面(index.html)中,确保代码在有DOM的上下文执行。

5. 补充GitHub相关权限

如果使用GitHub登录,当前host_permissions缺少GitHub授权相关地址,需补充:

"host_permissions": [
  "https://*.googleapis.com/*",
  "https://*.firebaseapp.com/*",
  "https://*.firebase.google.com/*",
  "https://github.com/login/oauth/authorize",
  "https://api.github.com/*"
]

内容的提问来源于stack exchange,提问作者Mireli Eyyubzade

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 12:55:56