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

未关闭 适合新手
#18,964 1 条评论 0 个 reaction 已指派 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 小时
30 天内合并 PR
78

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/flutterfire 的其他 Issue

查看 firebase/flutterfire 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。