且构网

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

Firebase无法在Chrome扩展内容脚本中加载

更新时间:2023-12-05 09:00:04

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. Inject the code you want to interact with firebase into the web page. It will be able to interact with the injected firebase code.

  2. 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.

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.