Skip to content

[firebase_app_check_web] Unhandled JS promise rejection on background token refresh network failure #18128

@davidmigloz

Description

@davidmigloz

Bug description

When Firebase AppCheck's JS SDK performs automatic background token refresh and the network is unavailable, it throws an unhandled promise rejection. In a Flutter web app, this surfaces as a JSObject: FirebaseError that reaches runZonedGuarded as a fatal unhandled error. The Dart firebase_app_check wrapper has no mechanism to intercept or suppress this.

Error

JSObject: FirebaseError: AppCheck: Fetch failed to connect to a network.
Check Internet connection. Original error: Load failed. (appCheck/fetch-network-error).

Context

Chrome Mobile iOS, app backgrounded, single transient network blip. Firebase recovers automatically on retry, so the error is purely noise — but it's reported as fatal by the Dart runtime.

Steps to reproduce

  1. Initialize Firebase AppCheck with activate(webProvider: ReCaptchaV3Provider(...)) in a Flutter web app
  2. Lose network connectivity (e.g., toggle airplane mode, or the browser suspends network when the app is backgrounded on mobile)
  3. Wait for the AppCheck SDK's automatic background token refresh to fire
  4. Observe unhandled JSObject: FirebaseError reaching runZonedGuarded

Expected behavior

Background token refresh network failures should be handled internally by the SDK (retry silently) without throwing unhandled promise rejections into the host app's zone.

Possible fix

The firebase_app_check_web platform implementation could zone-guard the JS interop bridge to catch transient errors from the JS SDK's internal timer-based refresh, or surface them through a dedicated error stream/callback rather than letting them propagate as unhandled exceptions.

Workaround

Filter FirebaseError events containing fetch-network-error in Sentry's beforeSend hook (or equivalent error reporting filter).

Flutter doctor

Flutter 3.41.4 • Dart 3.11.1

Platform

Web (Chrome Mobile iOS 145.0.7632)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions