4

I am creating a web extension both for chrome and firefox. I have integrated firebase UI and firebase auth. Google authentication works well on chrome extension. But on firefox extension/add-on it gives me the following error.

This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.

I tried couple of things, but none worked.

  1. Tried adding moz-extension://dhhjsbhjbajnsabjajbasjbhjasjh in authoirsed domain in firebase auth console. Validation error.
  2. Tried both pop up and redirect sign in methods.

Similar issue is faced by other developers while developing for cordova or ionic

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
Abhishek Batra
  • 1,539
  • 1
  • 18
  • 45

2 Answers2

6

Firefox extensions are not supported by Firebase Auth. You can file a feature request for this.

In the meantime, you can sign in the user via a popup opened from the extension and then CORS postMessage the result to the extension, making sure you check the origin of the extension before you do so. For example, assuming you are signing in with an OAuth provider, open a popup you own, sign in with Firebase, then pass the OAuth access token to the extension and then signInWithCredential from there.

bojeil
  • 29,642
  • 4
  • 69
  • 76
  • 1
    Popup will not work because of `Scripts may not close windows that were not opened by script` error. `postMessage` will not work on a new child tab because of `window.opener is null` error. So, at the moment there is no way Firebase Auth will work on Mozilla Firefox Extension. The worst thing is that Firebase Team could just allow to use `moz-extension://` protocol (they allow `chrome-extension://` protocol), but they don't do that. This problem exists for few years, but they don't do any fixes. Perhaps because of the competition between Google Chrome browser and Mozilla Firefox browser. – Amaimersion Apr 25 '19 at 14:37
  • That is why you call it from a background script. The same issue exists in Chrome extensions. The [documentation](https://firebase.google.com/docs/auth/web/google-signin#authenticate_with_firebase_in_a_chrome_extension) states this recommendation. – bojeil Apr 26 '19 at 18:49
  • You misunderstood me. I meant `signInWithPopup` method, not popup page of extension. `signInWithPopup` method will not work on Mozilla Firefox (if call it from Iframe, because `moz-extension://` protocol not supported) because of `Scripts may not close windows that were not opened by script` error. – Amaimersion Apr 28 '19 at 06:37
  • Can you please show some code - how to do this. I am trying to open popup by calling firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider()) . from background script --- gives error -- operation not supported – Mayank Kumar Chaudhari Jul 23 '20 at 06:12
1

I am not sure whether it is mandatory for you to use auth providers. If not, you can use firebase.auth().signInWithEmailAndPassword(email, password). This works well on firefox addon. Tested on resource page added with firefox addon.

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122