How to stream responses when using Fetch.fulfillRequest
We've got Fetch.fulfillRequest that allows us to give a response to an intercepted request.
I want to stream the response instead of giving it all at once. I'm working with a neverending http stream (SSE event source), so it seems like I cannot use fulfillRequest.
Does anyone know how to do that?
One way to do this is make use of the fact that on Chromium-based browsers the ServiceWorker uses Mojo to handle (streaming) requests between a WindowClient or Client (Worker) and the ServiceWorker, so it's possible to upload a ReadableStream, intercept that fetch() request in fetch event, and keep a fetch() request active indefinitely. See Half duplex stream for an example without using an extension, and a couple different ways persistent-serviceworker; see also Is it possible to establish an HTTP/2 connection over HTTP/1.1 with chrome as client?.
Note this repository is only related to the protocol types.
As for your question I think there is a similar issue on the Chromium tracker - https://crbug.com/332570739, Which was marked as Won't fix as there is currently no priority to work on this.
I guess we'll have to roll our own in the field.