Description
The specification talks about the initiator
but it's not exposed to JavaScript. At StackBlitz we have a concrete use case for WebContainer to run Node.js natively in the browser. More specifically, when intercepting fetch requests in a service worker, it would be very ideal to access the initiator
because we need to implement a custom cache layer (e.g. prefetch cache) inside the service worker. In our use case, requests to localhost
will never reach the browser's native network layer and are sent to the Node process (the server) running in another tab. To be able to implement e.g. the prefetch cache we'd have to know whether the request was initiated by rel=prefetch
.
My naive suggestion would be to expose the initiator
property on the request object.
interface Response {
initiator: 'download' | 'imageset' | 'manifest' | 'prefetch' | 'prerender' | 'xslt' | ''
}