Repository: puppeteer
Issue: [Feature]: Add page.evaluateStream function to stream data from page
Labels: feature,confirmed,P3

### Feature description

**Description**:

I would like to request the addition of a new function named `page.evaluateStream()` to Puppeteer. This function would allow streaming data directly from the page to the Node.js process, providing a more efficient way to interact with the page data in real time.

### Problem:
Currently, the best solution I have is to use `setInterval` combined with `page.evaluate` to poll for data at regular intervals, as shown below:

```javascript
// It can cause page stuttering
const buffer = [];
setInterval(async () => {
  const data = await page.evaluate(async function () {
    return data;
  }, 100);
  buffer.push(data);
});
```

While this solution barely works, it is not efficient. Additionally, using WebSockets to achieve real-time data streaming is not ideal because it requires setting up a server to handle communication, which adds unnecessary complexity.
I've seen people create browser extensions just to try to stream data readings from puppeteer.

### Proposed Solution:
A new function, `page.evaluateStream()`, would allow users to request data streaming directly from the page. This would simplify the process and improve performance by enabling continuous data retrieval without polling. Below is a hypothetical example of how this could be used:

```javascript
const browser = await puppeteer.launch({
  headless: false
});
const page = await browser.newPage();
await page.goto('https://pptr.dev/');

// New stream-based approach
const stream = await page.evaluateStream(() => {
  // This function would provide continuous data from the page
  return { some: 'data' };  // Example data
});

stream.on('data', (data) => {
  console.log('Received data:', data);
});
```

### Generator Function Example:
In addition to the previous approach, the function `evaluateStream` could also leverage JavaScript's `generator function` capabilities to yield data in real-time. This would allow users to write code similar to the following:

```javascript
const browser = await puppeteer.launch({
  headless: false
});
const page = await browser.newPage();
await page.goto('https://pptr.dev/');

// Using generator function to yield data
const stream = await page.evaluateStream(function* () {
  let count = 0;
  while (true) {
    yield { counter: count++ };  // Yielding new data every time
  }
});

stream.on('data', (data) => {
  console.log('Received data:', data);
});
```

In this example, the generator function allows for continuous yielding of data (like a counter), giving the flexibility to pause, resume, and manage the flow of data efficiently.

### Benefits:
1. **Improved performance**: Streaming data directly from the page would be much more efficient compared to using polling methods like `setInterval`.
2. **No external dependencies**: There would be no need for additional technologies like WebSockets or setting up a server.
3. **Simplified code**: Developers could avoid the complex and error-prone polling logic and rely on a clean, built-in function to stream data.
4. **Real-time data handling**: A native stream-based function would enable more seamless and performant real-time data interactions between Puppeteer and the client-side page.
5. **Enhanced flexibility**: The generator function approach adds the benefit of controlling the flow of data (e.g., pausing or yielding at specific intervals), which is ideal for complex scenarios requiring precise data streaming.

I believe this addition would greatly improve the user experience for Puppeteer users who need to interact with data on the page in real-time.