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

Đang mở Phù hợp với người mới
#18,964 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@LasseLegarth đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #18965 của @LasseLegarth — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, javascript
Lĩnh vực
web-dev

Hướng nghiên cứu

Đoạn mã liên quan là injectSrcScript trong lib/src/firebase_core_web.dart. Phương thức này chèn helper ff_trigger_* và chỉ chờ callback của nó, nên một import() động bị từ chối sẽ khiến completer bị treo ở trạng thái chờ. Hãy bắt đầu bằng việc đọc phương thức đó và helper JS mà nó chèn vào. Sau đó, tái hiện lỗi bằng cách gọi injectSrcScript với một URL không tồn tại và kiểm tra xem có bị timeout hay không. Hoàn thành khi future trả về kết thúc với lỗi nếu script không tải được, và có một test bao phủ trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Dart
Star
9.3k
Fork
4.1k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
78

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/flutterfire

Tất cả issue của firebase/flutterfire

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.