← Chrome 159 reference · All APIs
v159 · service worker · enabled by default
ServiceWorker Static Routing: Distinct TypeError message for cancelled race-network-and-fetch-handler fetch() requests
When a Service Worker matches a Static Routing rule with source: "race-network-and-fetch-handler" and calls fetch(event.request) inside its fetch handler, cancelling that deduplicated network request before response headers arrive (net::ERR_ABORTED) now rejects with TypeError("The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled.") instead of the generic TypeError("Failed to fetch").
at a glance
| Shipped in | Chrome 159 (desktop, Android, Android WebView), enabled by default — filed under “Enabled by default” in the milestone=159 listing and ChromeStatus API record |
|---|---|
| Feature kill switch | ServiceWorkerRaceNetworkRequestAbortedErrorMessage (FEATURE_ENABLED_BY_DEFAULT in third_party/blink/common/features.cc; no chrome://flags toggle) |
| Specification | W3C Service Workers — "race-network-and-fetch-handler"; WHATWG Fetch — fetch() (no IDL or spec change) |
| Intent | blink-dev Intent to Ship |
| Tracking bugs | crbug.com/584504247 (implementation); crbug.com/584629540 (follow-up standardized cancellation reporting) |
| Tests | Chromium browser tests (service_worker_browsertest.cc) & Blink unit tests (service_worker_global_scope_test.cc); WPT only checks TypeError type |
| ChromeStatus | 5124748525830144 — ServiceWorker Static Routing: Distinct TypeError message for cancelled race-network-and-fetch-handler fetch() requests |
why it exists
In Chromium’s Service Worker Navigation Preload API (event.preloadResponse), pre-settlement request cancellations (net::ERR_ABORTED) already reject with the dedicated message "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") rely on distinguishing expected race cancellations — such as an offline/cache fallback timer winning event.respondWith() or the user navigating away — from genuine network outages. Previously, Static Routing collapsed net::ERR_ABORTED into generic TypeError("Failed to fetch"), causing false-positive network error spikes in client telemetry and unnecessary fallback paths.
Syntax
This Chrome 159 change introduces no new WebIDL or specification syntax. It refines the rejection message string of fetch(event.request) inside a Service Worker fetch handler matched by an existing Static Routing rule registered via InstallEvent.addRoutes():
// Existing W3C Service Workers Static Routing registration (InstallEvent.addRoutes)
self.addEventListener("install", (event) => {
event.addRoutes({
condition: { urlPattern: { pathname: "/app/*" } },
source: "race-network-and-fetch-handler",
});
});
// Exact Chrome 159 TypeError rejection message when the deduplicated raced request
// (kRaceLoaderUsed) is aborted with net::ERR_ABORTED before response headers arrive
// (parallel to Navigation Preload's event.preloadResponse cancellation string):
// err instanceof TypeError === true
// err.message === "The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled."
This reference covers three parts of the contract: the distinct TypeError message, the loader deduplication & triggering conditions, and Navigation Preload telemetry parity.
Distinct TypeError rejection message
Inputs & outputs. When fetch(event.request) inside a Service Worker fetch handler consumes a deduplicated race-network-and-fetch-handler request and that network request is cancelled with net::ERR_ABORTED before response headers arrive, the promise returned by fetch(event.request) rejects with a TypeError whose message is verbatim:
The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled.
The exception constructor remains standard TypeError (satisfying Fetch’s requirement that network errors reject with a TypeError). Genuine network failures (such as offline disconnect, DNS resolution errors, TLS errors, or connection resets) continue to reject with Chromium’s standard TypeError("Failed to fetch").
Triggering conditions and loader deduplication
Inputs & outputs. In Blink’s ServiceWorkerGlobalScope::GetCustomFetchErrorMessage(net_error_code, request_data), the custom message is returned only when all four conditions hold simultaneously:
| Condition | Required state for custom message | Otherwise (fallback) |
|---|---|---|
| Network error code | net::ERR_ABORTED prior to response headers arriving | Standard TypeError("Failed to fetch") (or body stream error if aborted post-headers) |
| Race token presence | request_data carries a ServiceWorkerRaceNetworkRequestToken from a matched "race-network-and-fetch-handler" rule | Standard TypeError("Failed to fetch") for ordinary fetch() requests |
| Deduplicated loader state | Per-token loader state is kRaceLoaderUsed (the first deduplicated fetch(event.request) that bound to the raced loader) | Subsequent fetch(event.request) calls enter kFallbackDueToAlreadyConsumed and receive standard "Failed to fetch"; once MaybeRecordFetchError() clears the token to kNotFound, it cannot re-fire |
| Runtime feature flag | kServiceWorkerRaceNetworkRequestAbortedErrorMessage enabled (default in Chrome 159) | Standard TypeError("Failed to fetch") if disabled via Finch kill switch |
Parity with FetchEvent.preloadResponse and telemetry guidance
Inputs & outputs. The new message intentionally mirrors Chromium’s existing Navigation Preload cancellation string so telemetry pipelines migrating from event.preloadResponse to Static Routing can classify both consistently:
| Mechanism | Settling promise | Chromium pre-settlement cancellation TypeError.message |
|---|---|---|
| Navigation Preload | event.preloadResponse | "The service worker navigation preload request was cancelled before 'preloadResponse' settled." |
Static Routing (race-network-and-fetch-handler) | fetch(event.request) | "The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled." |
Temporary / non-standard caveat. Blink’s features.cc explicitly annotates kServiceWorkerRaceNetworkRequestAbortedErrorMessage with TODO(crbug.com/584629540) to replace this temporary custom message once standardized cancellation reporting is defined and implemented. Applications should use the message strictly for diagnostic/telemetry classification and never branch critical control flow exclusively on an engine-specific error string.
Errors, edge cases, and recovery
TypeErrorremains the exception class: callers catchingerr instanceof TypeErrorcontinue to work identically.- Strict equality on
"Failed to fetch"breaks if assumed for cancellations: any existing Service Worker code that explicitly matchederr.message === "Failed to fetch"to detect all fetch rejections (includingnet::ERR_ABORTEDcancellations on the deduplicatedkRaceLoaderUsedrequest) will no longer match cancelledrace-network-and-fetch-handlerfetches in Chrome 159+. Checkerr instanceof TypeErrorfor general fetch failures, and inspect the specific cancellation messages (forfetch()andpreloadResponse) only to suppress telemetry noise. - Invalid Static Routing rules: registering a
"race-network-and-fetch-handler"rule viaevent.addRoutes()when the Service Worker has nofetchevent listener rejects theaddRoutes()promise withTypeErrorper the W3C Service Workers spec.
addRoutes().
Context and exposure
Applies strictly inside a ServiceWorkerGlobalScope (Service Worker execution context, which requires a Secure Context) during a fetch event whose request matched a registered Static Routing rule with source: "race-network-and-fetch-handler". Window and Dedicated/Shared Worker fetch() calls are unaffected.
Lifecycle and state transitions
When a navigation or subresource request matches a "race-network-and-fetch-handler" rule during Service Worker activation/fetch dispatch, Chromium launches the network request in parallel with firing the Service Worker’s fetch event and attaches a one-time deduplication token. The first fetch(event.request) call inside the handler attaches to that in-flight race loader (kRaceLoaderUsed). If event.respondWith() settles first (for example from a cache fallback timer) or the client aborts the navigation before network response headers arrive, Chromium aborts the network loader with net::ERR_ABORTED, generates the distinct TypeError message for that pending fetch(event.request) promise, and clears the token state (kNotFound) during MaybeRecordFetchError().
Examples
Suppressing expected race-cancellation noise in Service Worker telemetry
const EXPECTED_CANCEL_MESSAGES = new Set([
"The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled.",
"The service worker navigation preload request was cancelled before 'preloadResponse' settled.",
]);
self.addEventListener("install", (event) => {
if (typeof event.addRoutes === "function") {
event.addRoutes({
condition: { urlPattern: { pathname: "/articles/*" } },
source: "race-network-and-fetch-handler",
});
}
});
self.addEventListener("fetch", (event) => {
// First fetch(event.request) binds to the deduplicated race loader (kRaceLoaderUsed);
// if timedCacheFallback wins before headers arrive, Chromium aborts it with net::ERR_ABORTED.
const networkPromise = fetch(event.request).catch((err) => {
// Distinguish expected pre-settlement race cancellation from real network outages
if (err instanceof TypeError && EXPECTED_CANCEL_MESSAGES.has(err.message)) {
return null; // Expected cancellation after cache fallback won; do not alert
}
reportNetworkOutageTelemetry(event.request.url, err);
throw err;
});
const timedCacheFallback = new Promise((resolve) => {
setTimeout(async () => {
const cached = await caches.match(event.request);
if (cached) resolve(cached);
}, 300);
});
event.respondWith(
Promise.race([
networkPromise.then((res) => res ?? caches.match(event.request)),
timedCacheFallback,
]).then((res) => res || new Response("Offline", { status: 503 })),
);
});
Source: ChromeStatus 5124748525830144; Blink service_worker_global_scope.cc.
Browser compatibility
| Browser | Distinct cancellation message | InstallEvent.addRoutes() (BCD) | Notes & evidence |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 159 | 123 | Enabled by default in Chrome 159 via ServiceWorkerRaceNetworkRequestAbortedErrorMessage per ChromeStatus 5124748525830144; Chrome 123–158 rejected with "Failed to fetch" |
| Edge | Chromium-based (mirror) | 123 (mirror) | Mirrors Chrome in BCD |
| Firefox | N/A | No (false) | No signal in ChromeStatus; InstallEvent.addRoutes() is not shipped in BCD |
| Safari | Engine-defined | 27 | No signal in ChromeStatus; Web IDL leaves TypeError.message strings implementation-defined |
Security and privacy
Refining the TypeError.message string inside the page’s own Service Worker exposes no cross-origin information, network timing side channel, or new capability beyond what the Service Worker already observes: the cancellation is triggered by the same origin’s fetch handler resolving event.respondWith() first or the client aborting its own navigation before response headers arrive. No response headers, status codes, or cross-origin error details are included in the message. ChromeStatus records no security risks and lists security/privacy reviews as Pending (checked 2026-11-24).
Specifications
| Specification | Section |
|---|---|
| W3C Service Workers | RouterSourceEnum — "race-network-and-fetch-handler" & InstallEvent.addRoutes() |
| WHATWG Fetch Standard | fetch() method (rejects with TypeError on network error) |
see also
- Chrome Platform Showcase — Cancelled race-network-and-fetch-handler TypeError (5 interactive concepts)
- MDN —
InstallEvent.addRoutes() - MDN —
FetchEvent.preloadResponse - Chrome for Developers — Service Worker Static Routing API
- ChromeStatus — ServiceWorker Static Routing: Distinct TypeError message for cancelled race-network-and-fetch-handler fetch() requests (5124748525830144)