且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase 未加载到 Chrome 扩展内容脚本中

更新时间:2023-12-05 08:47:40

您正在做的是使用 document.body.append(...) 注入 firebase 库.然后,您尝试从扩展程序内部访问 firebase 库,但 chrome 扩展程序被沙盒化,远离网页.您将 firebase 库注入到网页中,因此您的扩展程序无法直接访问它.您可以通过以下两种方式之一访问它:

What you are doing is injecting the firebase library by using document.body.append(...). Then, you are trying to access the firebase library from inside your extension, but chrome extensions are sandboxed away from the web page. You injected the firebase library into the web page, so it is not directly accessible to your extension. You can access it one of two ways:

  1. 将您想要与 firebase 交互的代码注入到网页中.它将能够与注入的 Firebase 代码进行交互.

  1. Inject the code you want to interact with firebase into the web page. It will be able to interact with the injected firebase code.

下载 firebase 库 javascript,并将 firebase 代码添加到您的 chrome 扩展清单.您必须下载它并将其与扩展程序的其余代码库一起打包.然后可以直接在您的扩展代码中使用它.

Download the firebase library javascript, and add the firebase code to your chrome extension manifest. You will have to download it and package it with the rest of your extension's codebase. It then can be used directly in your extension code.

我个人推荐 2.将所有代码保存在 chrome 沙箱中并且不向用户公开任何 firebase 代码(因为他们可以检查网页并查看您注入的代码)或网站更安全.如果您需要使用任何秘密或私钥连接到 Firebase,则尤其如此.

I personally recommend 2. It is more secure to keep all of the code inside the chrome sandbox and not expose any firebase code to the user (as they could inspect the web page and view your injected code) or website. This is especially true if you need to use any secret or private keys to connect to firebase.