ServiceWorker Static Routing: Distinct TypeError message for cancelled race-network-and-fetch-handler fetch() requests
- Category
- Miscellaneous
- Type
- New or changed feature
- Status
- Proposed (Chrome Proposed)
- Intent stage
- None
WPT details: Because TypeError message strings are implementation-defined and vary across browser engines, WPT only asserts the exception type. Tested in Chromium browser tests (content/browser/service_worker/service_worker_browsertest.cc) and Blink unit tests (third_party/blink/renderer/modules/service_worker/service_worker_global_scope_test.cc).
Summary
When a Service Worker matches a Static Routing rule with 'race-network-and-fetch-handler' and calls fetch(event.request) inside its fetch handler, Chromium deduplicates the network request. If that raced request is cancelled before response headers arrive (net::ERR_ABORTED)—for example, when an offline fallback timer resolves event.respondWith() first or the navigation is aborted—Chromium now rejects the fetch(event.request) promise with TypeError("The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled.") instead of the generic TypeError("Failed to fetch"). This matches Service Worker Navigation Preload (event.preloadResponse) and allows web applications to distinguish expected pre-settlement race cancellations from genuine network errors. Note: This is a small behavioral refinement to the already-shipped Service Worker Static Routing API with no IDL or specification changes. Because web applications may observe the updated TypeError message string, we are sending an Intent to Ship directly for web compatibility review.
Motivation
In Service Worker Navigation Preload (event.preloadResponse), Chromium already distinguishes pre-settlement cancellation (net::ERR_ABORTED) from genuine network failures by rejecting event.preloadResponse with "The service worker navigation preload request was cancelled before 'preloadResponse' settled.". Offline-capable web applications migrating from Navigation Preload to Static Routing ('race-network-and-fetch-handler') inspect this cancellation message to suppress expected cancellation noise in client error telemetry while still alerting on genuine network outages. Because 'race-network-and-fetch-handler' currently collapses net::ERR_ABORTED into TypeError("Failed to fetch"), migrating causes false-positive network error spikes and triggers unnecessary offline fallback paths.
Standards & signals
- Specification: https://w3c.github.io/ServiceWorker/#dom-routersourceenum-race-network-and-fetch-handler
- Firefox: No signal
- Safari: No signal
- Web developers: Positive — Requested by web applications migrating from Navigation Preload to Service Worker Static Routing 'race-network-and-fetch-handler'.
- Tracking bug: https://crbug.com/584504247
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=serviceworker-static-routing-distinct-typeerror-message-for-cancelled-race-network-and-fetch-handler-fetch-requests
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+ServiceWorker%20Static%20Routing%3A%20Distinct%20TypeError%20message%20for%20cancelled%20race-network-and-fetch-handler%20fetch()%20requests
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=ServiceWorker%20Static%20Routing%3A%20Distinct%20TypeError%20message%20for%20cancelled%20race-network-and-fetch-handler%20fetch()%20requests
- Baseline status: https://webstatus.dev/?q=ServiceWorker%20Static%20Routing%3A%20Distinct%20TypeError%20message%20for%20cancelled%20race-network-and-fetch-handler%20fetch()%20requests
Explainers: https://crbug.com/584504247