[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
维护者通常 1 天内回复
评估
- 难度
- 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 内容生成。
描述
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 小时
- 30 天内合并 PR
- 78
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/flutterfire 的其他 Issue
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)可能已有人在做 @SelaseKay 今天认领。 未关闭Needs Attention type: enhancement
难度 2/5 1-3 小时 新手友好度 70/100
firebase/flutterfire#18977 · 1 条评论 ·
维护者通常 1 天内回复
-
Needs Attention platform: android plugin: crashlytics type: enhancement
难度 4/5 3-5 天 新手友好度 48/100
firebase/flutterfire#18951 · 2 条评论 ·
维护者通常 1 天内回复
-
blocked: external dependency platform: web plugin: ai type: bug
难度 4/5 3-5 天 新手友好度 48/100
firebase/flutterfire#18938 · 2 条评论 ·
维护者通常 1 天内回复
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseException可能已有人在做 @SelaseKay 于 5 天前认领。 未关闭Needs Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
难度 4/5 3-5 天 新手友好度 52/100
firebase/flutterfire#18928 · 1 条评论 ·
维护者通常 1 天内回复
-
Needs Attention plugin: ai type: enhancement
难度 3/5 1-2 天 新手友好度 67/100
firebase/flutterfire#18917 ·
维护者通常 1 天内回复
查看 firebase/flutterfire 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree order未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
AlphaWaveSystems/flutter-probe#865 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
ubuntu/app-center#2306 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·