How to stream responses to an intercepted request using Chrome DevTools Protocol?

30 Views Asked by At

I'm intercepting a network request using the Fetch domain of Chrome Devtools Protocol. For more information, see Fetch.enable docs:

A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.

Currently, I'm using Fetch.fulfillRequest, but to use this, I need the entire body available. Calling the following code will fulfill/complete the request.

However, I don't want to fulfill/complete the request, I want to stream a chunk of data for it, and then stream more later. I'm doing this because I want to support apps that use long lived SSE connections.

        await sendCommand(source, 'Fetch.fulfillRequest', {
          requestId: params.requestId,
          responseCode: 200,
          responseHeaders: [
            { name: 'Content-Type', value: 'text/event-stream' },
            { name: 'Cache-Control', value: 'no-cache' },
            { name: 'Date', value: new Date().toUTCString() },
          ],
          body,
        })

This doesn't seem possible to me. Is there a workaround with or without using Chrome Devtools Protocol?

0

There are 0 best solutions below