使用 Firebase 进行 Chrome 扩展程序身份验证

Use Firebase for Chrome Extension authentication

我正在开发 chrome 扩展程序,正要设置身份验证时,我看到他们在 the page saying they are migrating authentication to firebase: https://firebase.google.com/docs/web/setup#prerequisites

上放置了一个通知

我正在尝试遵循他们对 "web setup" 的建议,但我认为扩展一定不一样,因为试图将初始化代码放入我的 background.js 我得到了错误:

Refused to load the script 'https://www.gstatic.com/firebasejs/live/3.0/firebase.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

我是不是把它加载到了错误的地方,或者只是有不同的扩展实现?

这是避免link rot:

的代码
// TODO: Replace with your project's customized code snippet
<script src="https://www.gstatic.com/firebasejs/3.0.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  databaseURL: '<your-database-url>',
  storageBucket: '<your-storage-bucket>'
};
firebase.initializeApp(config);

我用自己的自定义代码片段替换了它,并将嵌入的 link 放在 background.html 中,将 config/init 片段放在 background.js

您需要下载 firebase.js 并放入您的扩展程序中,然后使用亲戚 url 加载它。不允许您的扩展程序访问外部脚本。

将此添加到您的 manifest.json:

"content_security_policy":"script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'"

这样您就不会违反您收到的错误中提到的内容安全政策。