← 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").

Limited availability — Chromium-specific implementation-defined error message (base InstallEvent.addRoutes() is Chrome 123+, Safari 27, not in Firefox)

  • Chrome · 159 (desktop, Android, WebView)
  • Edge · Chromium-based (BCD mirror)
  • Firefox · No signal (addRoutes() unsupported in BCD)
  • Safari · No signal (addRoutes() in 27; message engine-defined)

BCD api/InstallEvent.json records base InstallEvent.addRoutes() in Chrome 123+ and Safari 27 (unsupported in Firefox; checked 2026-11-24). Because Web IDL explicitly leaves TypeError.message strings implementation-defined, this distinct message is Chromium-specific and has no webstatus.dev web-feature or BCD subfeature.

at a glance

Shipped inChrome 159 (desktop, Android, Android WebView), enabled by default — filed under “Enabled by default” in the milestone=159 listing and ChromeStatus API record
Feature kill switchServiceWorkerRaceNetworkRequestAbortedErrorMessage (FEATURE_ENABLED_BY_DEFAULT in third_party/blink/common/features.cc; no chrome://flags toggle)
SpecificationW3C Service Workers — "race-network-and-fetch-handler"; WHATWG Fetch — fetch() (no IDL or spec change)
Intentblink-dev Intent to Ship
Tracking bugscrbug.com/584504247 (implementation); crbug.com/584629540 (follow-up standardized cancellation reporting)
TestsChromium browser tests (service_worker_browsertest.cc) & Blink unit tests (service_worker_global_scope_test.cc); WPT only checks TypeError type
ChromeStatus5124748525830144 — 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.

Source: ChromeStatus motivation (5124748525830144); crbug.com/584504247.

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.

Source: W3C Service Workers Static Routing; Blink service_worker_global_scope.cc.

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").

Source: Blink service_worker_global_scope.cc (GetCustomFetchErrorMessage); ChromeStatus summary (5124748525830144).

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:

Exact gating rules for the distinct cancellation TypeError message in Chrome 159
ConditionRequired state for custom messageOtherwise (fallback)
Network error codenet::ERR_ABORTED prior to response headers arrivingStandard TypeError("Failed to fetch") (or body stream error if aborted post-headers)
Race token presencerequest_data carries a ServiceWorkerRaceNetworkRequestToken from a matched "race-network-and-fetch-handler" ruleStandard TypeError("Failed to fetch") for ordinary fetch() requests
Deduplicated loader statePer-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 flagkServiceWorkerRaceNetworkRequestAbortedErrorMessage enabled (default in Chrome 159)Standard TypeError("Failed to fetch") if disabled via Finch kill switch
Source: Blink service_worker_global_scope.cc; Blink service_worker_global_scope_test.cc.

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:

Comparison of Chromium pre-settlement cancellation TypeError messages
MechanismSettling promiseChromium pre-settlement cancellation TypeError.message
Navigation Preloadevent.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.

Source: ChromeStatus motivation (5124748525830144); Blink features.cc (TODO crbug.com/584629540).

Errors, edge cases, and recovery

Source: ChromeStatus interop & compatibility risks; W3C Service Workers 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.

Source: W3C Service Workers; Blink service_worker_global_scope.cc.

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().

Source: Blink service_worker_global_scope.cc; Blink service_worker_global_scope_test.cc.

Examples

Live interactive example: Fallback-timer race (also see Error taxonomy, Telemetry noise filter, App-shell revalidation, and Fetch shape inspector).Source: Chrome Platform Showcase — ServiceWorker Static Routing cancelled race TypeError

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

Support for the distinct cancellation TypeError message alongside BCD support for InstallEvent.addRoutes() (checked 2026-11-24). Because exception message strings are implementation-defined in Web IDL, BCD does not track this message separately.
BrowserDistinct cancellation messageInstallEvent.addRoutes() (BCD)Notes & evidence
Chrome (desktop, Android, WebView)159123Enabled by default in Chrome 159 via ServiceWorkerRaceNetworkRequestAbortedErrorMessage per ChromeStatus 5124748525830144; Chrome 123–158 rejected with "Failed to fetch"
EdgeChromium-based (mirror)123 (mirror)Mirrors Chrome in BCD
FirefoxN/ANo (false)No signal in ChromeStatus; InstallEvent.addRoutes() is not shipped in BCD
SafariEngine-defined27No signal in ChromeStatus; Web IDL leaves TypeError.message strings implementation-defined
Source: BCD api/InstallEvent.json; ChromeStatus API record.

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).

Source: ChromeStatus record (5124748525830144); W3C Service Workers Security Considerations.

Specifications

see also