[w3c/ServiceWorker] Provide a standardized way to distinguish cancelled requests from network errors in Service Worker fetch handler (especially race-network-and-fetch-handler) (Issue #1857)

sisidovski created an issue (w3c/ServiceWorker#1857)

When a Service Worker matches a Static Routing rule with [`race-network-and-fetch-handler`](https://w3c.github.io/ServiceWorker/#dom-routersourceenum-race-network-and-fetch-handler) and calls `fetch(event.request)` inside its `fetch` event handler, the user agent deduplicates/races the network request with the Service Worker execution ([#handle-fetch](https://w3c.github.io/ServiceWorker/#handle-fetch), [#lookup-race-response](https://w3c.github.io/ServiceWorker/#lookup-race-response)).

If that raced request is cancelled before response headers arrive—for example, when the user aborts/navigates away from the page, or when an offline fallback timer in the Service Worker resolves `event.respondWith()` first—`fetch(event.request)` rejects with a generic `TypeError` per [WHATWG Fetch](https://fetch.spec.whatwg.org/#concept-main-fetch).

For large offline-capable web applications, benign pre-settlement request cancellations and genuine network failures (such as the device being offline or a server/DNS failure) require completely different handling:
1. **Error telemetry & alerting**: Genuine network failures during online sessions are logged to monitor production reliability, whereas user navigation cancellations are expected and must be filtered out to avoid false-positive error spikes.
2. **Offline fallback paths**: Genuine network failures should trigger offline fallback logic (e.g., serving cached fallback documents from IndexedDB/Cache Storage), whereas cancelled requests should not trigger unnecessary fallback work.

In Service Worker Navigation Preload (`event.preloadResponse`), Chromium has historically rejected `event.preloadResponse` with a distinct exception message string when the preload request is cancelled before settling (`"The service worker navigation preload request was cancelled before 'preloadResponse' settled."`) versus when it fails due to an actual network error. Because the platform provided no structured API to distinguish these cases, web applications ended up parsing `error.message` to filter out benign cancellations.

When migrating from Navigation Preload to Static Routing (`race-network-and-fetch-handler`), `fetch(event.request)` collapses pre-settlement cancellations into the generic `TypeError("Failed to fetch")`. To unblock web applications migrating to `race-network-and-fetch-handler` in the short term, Chromium introduced a temporary workaround to use a distinct `TypeError` message string (`"The service worker race-network-and-fetch-handler request was cancelled before 'fetch()' settled."`) for aborted raced requests (https://crbug.com/584504247, [blink-dev thread](https://groups.google.com/a/chromium.org/d/msgid/blink-dev/6af42035.c4d90b0f.20186.0030.GAE%40google.com)).

However, relying on implementation-defined exception `message` strings is fragile and undesirable for interoperability. We would like to define a proper, standardized mechanism so web applications do not need to parse error message strings, and remove Chromium's custom message workaround once a standard solution is available (tracked in https://crbug.com/584629540).

https://github.com/whatwg/fetch/issues/526 discusses the broader desire to expose more granular information when `fetch()` rejects with a network error. A major concern in `whatwg/fetch#526` is that exposing underlying network error details (such as DNS, TLS, or connection reset reasons) across origins can leak sensitive network state.

We would appreciate feedback from implementers and spec editors on the best direction to standardize this (either in Service Worker, Fetch, or both):

1. **Structured error type or property on the rejected `fetch()` error (with WHATWG Fetch / `whatwg/fetch#526`)**:
   - Rejecting with a specific `TypeError` subclass, `DOMException`, or attaching a structured property / `Error.cause` (e.g., indicating that the fetch was cancelled prior to settlement rather than failing due to a network error).
2. **Abort signal propagation on `FetchEvent` / `event.request.signal`**:
   - Propagating client/race cancellation to `event.request.signal` (or a dedicated signal on `FetchEvent`) so the Service Worker can inspect `.aborted` / `.reason` or observe an `AbortError`.
   - *Note*: In Chromium today, `event.request.signal` on a Service Worker `FetchEvent` is not wired to browser-side navigation cancellation, and changing existing `fetch(event.request)` rejections on cancelled requests from `TypeError` to `DOMException("AbortError")` could have backward-compatibility implications for existing Service Workers if done unconditionally.
3. **Service Worker / `FetchEvent`-specific indicator**:
   - If modifying general `fetch()` rejection behavior is too broad, exposing cancellation state specifically on `FetchEvent` or for deduplicated `race-network-and-fetch-handler` requests.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1857
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/1857@github.com>

Received on Wednesday, 11 November 2026 15:18:46 UTC