Search code examples
javascriptfirebasegoogle-cloud-firestorefirefox-addonbrowser-extension

How to access firebase firestore from firefox addon?


I am developing addon for updating some simple data to firestore. From documentation for firebase for web I get following script tags

<script src="/__/firebase/7.16.1/firebase-app.js"></script>
<script src="/__/firebase/init.js"></script>
<script src="/__/firebase/7.15.0/firebase-auth.js"></script>
<script src="/__/firebase/7.15.0/firebase-firestore.js"></script>

I added these tags in the page that is loaded by addon. But it says

Loading failed for the <script> with source “moz-extension://dadb8575-946a-4f4b-bcb1-43bfe949b7ea/__/firebase/7.16.1/firebase-app.js”.

My question is how do I integrate firebase auth and database to my addon?


Solution

  • The script URL syntax you're using that starts with two underscores only works with HTML pages hosted from Firebase Hosting. If you're using HTML from another source, you'll have to use a different URL. You can either package up the scripts and host them wherever you want, or you can use the CDN URLs as shown in the documentation. Be sure to switch to the "From the CDN" tab in the docs.

    For example:

      <!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services -->
    
      <!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
      <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js"></script>
    
      <!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
      <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-analytics.js"></script>
    
      <!-- Add Firebase products that you want to use -->
      <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-auth.js"></script>
      <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-firestore.js"></script>
    

    You will need to create your own replacement for /__/firebase/init.js, since that has the code that initializes Firebase using your project's unique settings.