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

Open Beginner friendly
#18,964 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@LasseLegarth is already working on this.

Since Nov 13, 2026.

  • #18965 by @LasseLegarth — open

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

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.

Dominant language
Dart
Stars
9.3k
Forks
4.1k
Avg merge
2d 10h
Merged PRs (30d)
78

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/flutterfire

All issues in firebase/flutterfire

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.