devtools-protocol icon indicating copy to clipboard operation
devtools-protocol copied to clipboard

How to stream responses when using Fetch.fulfillRequest

Open ben-xD opened this issue 2 years ago • 1 comments

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?

ben-xD avatar Jan 18 '24 21:01 ben-xD

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

guest271314 avatar Apr 13 '25 14:04 guest271314

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.

Lightning00Blade avatar Jul 31 '25 20:07 Lightning00Blade

I guess we'll have to roll our own in the field.

guest271314 avatar Aug 01 '25 00:08 guest271314