[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- dart, javascript
- Ambito
- web-dev
Direzione di ricerca
Il codice rilevante è injectSrcScript in lib/src/firebase_core_web.dart, che inserisce l'helper ff_trigger_* e attende solo il suo callback, quindi un import() dinamico rifiutato lascia il completer in sospeso. Inizia leggendo quel metodo e l'helper JS che inserisce, poi riproduci il problema chiamando injectSrcScript con un URL inesistente e verifica se va in timeout. È fatto quando il future restituito si completa con un errore se lo script non viene caricato, e un test copre questo caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Core
Which platforms are affected?
Web
Description
On web, Firebase.initializeApp() loads the Firebase JS SDK from www.gstatic.com with a dynamic import() per service (injectSrcScript in lib/src/firebase_core_web.dart). The injected helper looks like this:
window.ff_trigger_firebase_core = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/<version>/firebase-app.js"));
};
and the Dart side only waits for the callback:
Completer completer = Completer();
globalContext.callMethod('ff_trigger_$windowVar'.toJS, (JSAny module) {
globalContext[windowVar] = module;
globalContext.delete('ff_trigger_$windowVar'.toJS);
completer.complete();
}.toJS);
await completer.future;
If the import() rejects (network drop, request blocked, CDN error), the callback is never called, so the completer never completes and Firebase.initializeApp() never returns. The rejection itself only shows up as an unhandled promise rejection (Safari: TypeError: Importing a module script failed., Chrome: TypeError: Failed to fetch dynamically imported module: ...).
For the user this is an app that never starts, with no error the app can catch, retry or show. We see this in production on iOS Safari (13 events in 8 months).
Expected: Firebase.initializeApp() fails with an error when one of the SDK scripts cannot be loaded, so the app can handle it (show an error, retry, reload).
Reproducing the issue
Call injectSrcScript (the method initializeApp uses) with a URL that cannot be loaded:
final coreWeb = FirebaseCoreWeb();
await coreWeb
.injectSrcScript('${web.window.location.origin}/does-not-exist.js', 'firebase_missing')
.timeout(const Duration(seconds: 10));
// TimeoutException: Future not completed
Or in an app: block www.gstatic.com in DevTools (Network request blocking) and call Firebase.initializeApp(). It never returns and runApp is never reached.
Firebase Core version
latest main (firebase_core_web)
Flutter Version
stable
Relevant Log Output
Unhandled Promise Rejection: TypeError: Importing a module script failed.
Flutter dependencies
n/a
Additional context and comments
The helper is already an async function, so it returns a promise that rejects when import() fails. Awaiting that promise instead of only the callback is enough to surface the error. I have a PR ready.
- Lingua principale
- Dart
- Stelle
- 9.3k
- Fork
- 4.1k
- Merge medio
- 2g 10h
- PR unite (30g)
- 78
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)Forse già presa @SelaseKay l’ha presa oggi. ApertaNeeds Attention type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
firebase/flutterfire#18977 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Needs Attention platform: android plugin: crashlytics type: enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/flutterfire#18951 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
blocked: external dependency platform: web plugin: ai type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/flutterfire#18938 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseExceptionForse già presa @SelaseKay l’ha presa 5 giorni fa. ApertaNeeds Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
firebase/flutterfire#18928 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Needs Attention plugin: ai type: enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
firebase/flutterfire#18917 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di firebase/flutterfire
Issue simili
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
[BUG] 172.2* 排除域名包含公网IPAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
AlphaWaveSystems/flutter-probe#865 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
ubuntu/app-center#2306 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·