Skip to content

Commit 852942c

Browse files
Improve firebase initialization logic
Add check to prevent fatal error on script reload. In Firebase V9 Compat, if firebase.initializeApp() is called twice (which can happen if a mobile browser aggressively caches and re-executes the script, or if you hot-reload your local server), Firebase throws a fatal internal error: "Firebase App named '[DEFAULT]' already exists." While our silent catch block would hide this error from the participant, it's methodologically safer to prevent the error from firing at all.
1 parent 25648b6 commit 852942c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

code/firebase-config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const firebaseConfig = {
1313
// Defensive execution to prevent UI thread blocking if the CDN fails to load
1414
if (typeof firebase !== 'undefined') {
1515
try {
16-
firebase.initializeApp(firebaseConfig);
16+
// Prevent fatal error if the browser aggressively reloads the script
17+
if (typeof firebase.initializeApp === 'function' && (!firebase.apps || firebase.apps.length === 0)) {
18+
firebase.initializeApp(firebaseConfig);
19+
}
1720
} catch (e) {
1821
// Absolute silence mandated. No console.error here.
1922
// The failure will be naturally caught by experiment.js falling back to localStorage.

0 commit comments

Comments
 (0)