Firebase not getting loaded in chrome extension content script

前端 未结 1 1266
北海茫月
北海茫月 2020-12-19 15:49

I\'m trying to load Firebase inside my chrome extension\'s content script:

var script   = document.createElement(\"script\")
script.type  = \"text/javascript         


        
相关标签:
1条回答
  • 2020-12-19 16:21

    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.

    0 讨论(0)
提交回复
热议问题