playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Allow route fulfillment with a readable stream body

Open zakhenry opened this issue 1 year ago • 1 comments

🚀 Feature Request

Currently, Route.fulfill only accepts string|Buffer as body type. Add nodejs type ReadableStream to permit streamed calls.

Example

const bodyStream = new Readable();

await page.route('**/*', async route => {
 route.fulfill({
    status: 200,
    contentType: 'application/grpc-web+proto',
    body: bodyStream
  });
});

// @todo interact with page

bodyStream.push(chunk);
// @todo  assert on DOM state

bodyStream.push(chunk);
// @todo assert on updated DOM state

bodyStream.destroy();
// @todo assert request completed

Motivation

There are several use-cases where this is useful:

  1. stubbing grpc-web calls that are server streaming - the test script could push events into the stream and assert the expected in-progress result is displayed in the webview
  2. stubbing server-sent events
  3. stubbing streams of other kinds (live video?)

zakhenry avatar Nov 13 '24 01:11 zakhenry

This would be very useful for our workflow as well. Would appreciate if this could get onto the roadmap

gurkohli avatar Nov 25 '24 23:11 gurkohli

This would hugely help with development. I was trying to use MSW and also wrote my own Express mock server, but integrating these tools with playwright tests to apply overrides, has proven unsuccessful so far. I was hoping to use some libraries, which were claiming to be bridges between Playwright and MSW, but they don't work anymore.

lepris avatar Sep 23 '25 09:09 lepris

Any update on this?

mrasoahaingofig avatar Sep 29 '25 08:09 mrasoahaingofig