[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 62/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- dart, javascript
- Área
- web-dev
Línea de trabajo
El código relevante es injectSrcScript en lib/src/firebase_core_web.dart, que inserta el helper ff_trigger_* y solo espera a su callback, así que un import() dinámico rechazado deja el completer pendiente. Empieza leyendo ese método y el helper de JS que inserta. Luego reproduce el problema llamando a injectSrcScript con una URL que no existe y comprueba si se produce un timeout. Está terminado cuando el future devuelto se completa con un error si el script no se carga, y un test cubre ese caso.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Dart
- Estrellas
- 9.3k
- Forks
- 4.1k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 78
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)Posiblemente ocupada @SelaseKay la tomó hoy. AbiertoNeeds Attention type: enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
firebase/flutterfire#18977 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Needs Attention platform: android plugin: crashlytics type: enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
firebase/flutterfire#18951 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
blocked: external dependency platform: web plugin: ai type: bug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
firebase/flutterfire#18938 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseExceptionPosiblemente ocupada @SelaseKay la tomó hace 5 días. AbiertoNeeds Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
firebase/flutterfire#18928 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Needs Attention plugin: ai type: enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
firebase/flutterfire#18917 ·
Los mantenedores suelen responder en 1 día
Todos los issues de firebase/flutterfire
Issues similares
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
[BUG] 172.2* 排除域名包含公网IPAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
AlphaWaveSystems/flutter-probe#865 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
ubuntu/app-center#2306 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·