Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load a large content #522

Closed
derevnjuk opened this issue Feb 1, 2023 · 0 comments · Fixed by #523
Closed

Unable to load a large content #522

derevnjuk opened this issue Feb 1, 2023 · 0 comments · Fixed by #523
Labels

Comments

@derevnjuk
Copy link
Contributor

derevnjuk commented Feb 1, 2023

Environment

Component Version
Node.js v16.19.0
Client (Chrome/Chromium/...) Chrome/Chromium
OS running Node.js MacOS
OS running the client MacOS
chrome-remote-interface v0.32.0

Is the client running in a container? NO

Description

Unable to retrieve a response body that is greater than 100MB. The maximum size of a message that can be sent through Chrome DevTools is 256 MB: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_http_handler.cc;l=90?q=kSendBufferSizeForDevTools&ss=chromium

Steps to reproduce

  1. Server an index.html file that loads a JSON greater than 100MB in size. Example:
index.js
const express = require('express');
const app = express();

app.get('/', (_, res) => res.sendFile('index.html', { root: __dirname }));

app.get('/api/keys', (_, res) =>
 res.json({
   keys: Array(1000)
     .fill(0)
     .map((_noop, idx) => ({
       key: randomBytes(100000).toString('hex'),
       id: idx
     }))
 })
);

app.listen(3000, () => {
 console.log("Server started on port 3000");
});
index.html
<p id="result"></p>
<script>
 const result = document.querySelector("#result");

 fetch("/api/keys")
   .then((response) => response.json())
   .then((data) => {
     result.innerHTML = `Found ${data.keys.length} keys`
   });
</script>
  1. Open the root page and initiate the listening process for incoming requests.
const maxSize = 256 * 1024 * 1204;
const client = await CDP();

client.Network.enable({
    maxResourceBufferSize: maxSize,
    maxTotalBufferSize: maxSize,
});

let targetRequestId;

client.Network.on('requestWillBeSent', async ({request, requestId}) => {
    if (request.url.includes('/api/keys')) {
        targetRequestId = requestId;
    }
});
client.Network.on('loadingFinished', async ({requestId}) => {
    try {
        if (!targetRequestId || targetRequestId !== requestId) {
            return;
        }
        console.log(`Loading the content for ${requestId}`);
        const res = await client.Network.getResponseBody({requestId});
        console.log(`Content loaded: ${Buffer.from(res.body).byteLength} bytes`);
    } catch (e) {
        console.error('Unable to load the content due to the error:');
        console.error(e);
    }
});
client.once('ready', () => client.Page.navigate({url: 'http://localhost:3000'}));
client.once('disconnect', () => console.log('The socket disconnected.'));

Actual behavior

The connection has been unexpectedly terminated, resulting in the inability to retrieve the content.

For details please refer to puppeteer/puppeteer#4543 and NeuraLegion/cypress-har-generator#177

derevnjuk added a commit to derevnjuk/chrome-remote-interface that referenced this issue Feb 1, 2023
derevnjuk added a commit to NeuraLegion/cypress-har-generator that referenced this issue Feb 13, 2023
)

The maximum size of a single resource that can be preserved is 10MB. If
you need to receive a larger response body, you should adjust the
`maxResourceBufferSize` and `maxTotalBufferSize` accordingly:

```js
cy.recordHar({
  maxTotalBufferSize: 1024 ** 3,
  maxResourceBufferSize: 100 * 1024 ** 2
});
```

However, note that the resource buffer size cannot be greater than 256MB
due to [the
limit](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_http_handler.cc;l=90?aq=kSendBufferSizeForDevTools&ss=chromium)
for WebSocket connections in Chrome.

closes #177 
depends-on: cyrus-and/chrome-remote-interface#522
@cyrus-and cyrus-and added the bug label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants