demo · v138
Service Worker sees prefetched requests
In Chrome 138 the active Service Worker's fetch handler is now invoked for requests originated by Speculation Rules prefetch. Register the worker below, inject a prefetch, watch the worker log the request — with the new Sec-Purpose: prefetch hint visible.
checking support…
the code
// sw.js
self.addEventListener("fetch", (e) => {
// 138+: also called for SpeculationRules prefetch requests.
const purpose = e.request.headers.get("Sec-Purpose") || "(none)";
// log purpose, e.request.url, e.request.mode etc.
});
see also
- SW support for SR prefetch — feature index
- ChromeStatus entry