microsoft / microsoft/playwright

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

Open
#33,564 3 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-collecting-feedback
Dominant language
TypeScript
Stars
96.4k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

🚀 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?)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Route.fulfill and page.route entry points, then trace how the current string|Buffer body is handled. Check how a Node.js Readable stream would flow through fulfillment and verify the grpc-web, server-sent events, and incremental-body examples complete as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.