[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
Maintainer thường phản hồi trong vòng 1 ngày
Đá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ả
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)Có thể đã có người làm @SelaseKay đã nhận hôm nay. Đang mởNeeds Attention type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
firebase/flutterfire#18977 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs Attention platform: android plugin: crashlytics type: enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
firebase/flutterfire#18951 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked: external dependency platform: web plugin: ai type: bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
firebase/flutterfire#18938 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseExceptionCó thể đã có người làm @SelaseKay đã nhận 5 ngày trước. Đang mởNeeds Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
firebase/flutterfire#18928 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs Attention plugin: ai type: enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
firebase/flutterfire#18917 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của firebase/flutterfire
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
[BUG] 172.2* 排除域名包含公网IPĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
AlphaWaveSystems/flutter-probe#865 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ubuntu/app-center#2306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·