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

オープン 初心者向け
#18,964 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@LasseLegarth がすでに取り組んでいます。

2026年11月13日 から。

  • #18965 @LasseLegarth による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
dart, javascript
領域
web-dev

調査の方向性

関連するコードは lib/src/firebase_core_web.dart の injectSrcScript です。このメソッドは ff_trigger_* ヘルパーを注入し、そのコールバックのみを待機するため、拒否された動的な import() があると completer が保留のまま残ります。まずこのメソッドと、注入される JS ヘルパーを読んでください。次に、存在しない URL を指定して injectSrcScript を呼び出し、タイムアウトするかどうかを確認して問題を再現してください。スクリプトの読み込みに失敗したときに、返される future がエラーで完了し、そのケースをテストが網羅していれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Dart
スター
9.3k
フォーク
4.1k
平均マージ
2日 10時間
マージ済み PR(30日)
78

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/flutterfire のほかの issue

firebase/flutterfire の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。