Description
[REQUIRED] Describe your environment
- Operating System version: MacOs
- Browser version: 94.0.4606.71
- Firebase SDK version: 9.1.2
- Firebase Product: auth
[REQUIRED] Describe the problem
When trying to signin with Google (signInWithPopup) in a Chrome extension with manifest v3 (ie in a service worker), I trigger errors, popup does not open and one cannot log in.
Steps to reproduce:
The popup script (popup.js) calls the background script via message passing and asks for login.
The background script (background.js) initializes firebase and auth and calls
signInWithPopup(auth, provider)
.then((result) => {
// ...
}).catch((error) => {
console.log("in popup error callback", error);
});
The specific error is in resolver.ts, line 38:
where auth._popupRedirectResolver
is null
.
This is after replacing
const auth = getAuth(firebaseApp);
with
const auth = initializeAuth(firebaseApp, {persistence: indexedDBLocalPersistence});
Without that, I would get a known error about missing window
when initializing auth.
I suppose that this still has to do with service workers having not enough access to open a popup window. I would very much like to know if this is true, and specifically, if once manifest v2 is fully deprecated, there won't be any way to do signin with Google in chrome extensions anymore.
Relevant Code:
background.js
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.2/firebase-app.js';
import { initializeAuth, indexedDBLocalPersistence, onAuthStateChanged, getIdToken, signOut, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/9.1.2/firebase-auth.js";
const firebaseApp = initializeApp({
apiKey: "xxx",
authDomain: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
measurementId: "xxx"
});
const provider = new GoogleAuthProvider();
const auth = initializeAuth(firebaseApp, {persistence: indexedDBLocalPersistence});
//...
signInWithPopup(auth, provider)
.then((result) => {
console.log("in popup callback");
}).catch((error) => {
console.log("in popup error callback", error); // <--- this gets triggered.
});
I realize that this maybe more of a Chrome Extension problem than a bug in firebase-auth, but my asks on crx and stackexchange have been met with stony silence. I suspect the real answer is that there is at present no way to make signInWithPopup work in MV3 at all(MV2 is working fine), and that the Crx team is not able to publicly state that Chrome extensions in the future will not have social signins (or 2FA signins). But I would very much like to know where I stand so I can plan accordingly.
Thank you very much in advance for clarifying!