[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load

Aperta Adatta ai principianti
#18,964 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@LasseLegarth ci sta già lavorando.

Dal 13/11/2026.

  • #18965 di @LasseLegarth — aperta

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

Needs Attention platform: web plugin: core reproduced type: bug
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/flutterfire

Tutte le issue di firebase/flutterfire

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.