[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- dart, javascript
- Domain
- web-dev
Research direction
The relevant code is injectSrcScript in lib/src/firebase_core_web.dart, which injects the ff_trigger_* helper and waits only on its callback, so a rejected dynamic import() leaves the completer pending. Start by reading that method and the JS helper it injects, then reproduce by calling injectSrcScript with a URL that does not exist and checking whether it times out. Done means the returned future completes with an error when the script fails to load, and a test covers that case.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Dart
- Stars
- 9.3k
- Forks
- 4.1k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 78
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)Possibly taken @SelaseKay claimed this today. OpenNeeds Attention type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
firebase/flutterfire#18977 · 1 comment ·
Maintainers usually reply within 1 day
-
Needs Attention platform: android plugin: crashlytics type: enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
firebase/flutterfire#18951 · 2 comments ·
Maintainers usually reply within 1 day
-
blocked: external dependency platform: web plugin: ai type: bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
firebase/flutterfire#18938 · 2 comments ·
Maintainers usually reply within 1 day
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseExceptionPossibly taken @SelaseKay claimed this 6 days ago. OpenNeeds Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
Difficulty 4/5 3-5 days Newbie friendliness 52/100
firebase/flutterfire#18928 · 1 comment ·
Maintainers usually reply within 1 day
-
Needs Attention plugin: ai type: enhancement
Difficulty 3/5 1-2 days Newbie friendliness 67/100
firebase/flutterfire#18917 ·
Maintainers usually reply within 1 day
All issues in firebase/flutterfire
Similar issues
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
StabilityNexus/Zplit#77 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
AlphaWaveSystems/flutter-probe#865 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ubuntu/app-center#2306 ·
Maintainers usually reply within 1 day