puppeteer: response.buffer() rejects for selected resources
The promise returned by response.buffer() consistently rejects for certain resources. This makes it impossible to collect information about certain resources that can only be obtained from the buffer, such as the length of the resource.
The problem seems to particularly affect video/media files. (Perhaps because partial requests are involved?)
To reproduce:
'use strict';
const URL = 'https://www.quirksmode.org/html5/tests/video.html';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.on('response', response => {
const url = response.url;
if (!url.startsWith('data:') && response.ok) {
response.buffer().then(
b => {
console.log(`${response.status} ${url} ${b.length} bytes`);
},
e => {
console.error(`${response.status} ${url} failed: ${e}`);
}
);
}
});
await page.goto(URL, { waitUntil: 'networkidle0' });
})();
Actual:
200 https://www.quirksmode.org/html5/tests/video.html 2905 bytes
200 https://www.quirksmode.org/quirksmode.css 16360 bytes
200 https://www.quirksmode.org/quirksmode.js 22540 bytes
200 https://www.quirksmode.org/pix/footer_bg.gif 312 bytes
206 https://www.quirksmode.org/html5/videos/big_buck_bunny.webm failed: Error: Protocol error (Network.getResponseBody): No data found for resource with given identifier undefined
206 https://www.quirksmode.org/html5/videos/big_buck_bunny.ogv failed: Error: Protocol error (Network.getResponseBody): No data found for resource with given identifier undefined
206 https://www.quirksmode.org/html5/videos/big_buck_bunny.webm 24804 bytes
206 https://www.quirksmode.org/html5/videos/big_buck_bunny.ogv 66642 bytes
Expected:
As above, but without the “Error: Protocol error (Network.getResponseBody): No data found for resource with given identifier undefined” messages.
The “broken” resources seem to be associated with 206 responses.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 23 (8 by maintainers)
Update reproduce code for Puppeteer 1:
In my case I was listening to the
'response'
event when I should have been listening to the'requestfinished'
event.@anaulin I was able to reproduce this with disabled JavaScript. It looks like server sometimes aborts the request - the video element on the page is non-functional indeed when this happens:
@aslushnikov you are absolutely right that i see the video blinking in again when i load that page – that’s a good catch, hadn’t noticed that before.
I also added that extra log line, and the error text seems to always be
net::ERR_ABORTED
:Full script (for future reference):
@aslushnikov thanks for getting to the bottom of that – it is consistent with the
net::ERR_ABORTED
errors I was seeing. Looks like the issue for us is really this server breaking the connection, and not a Puppeteer issue after all.Also experiencing this issue when intercepting a response whose
.buffer()
resolves to a pdf file.I’m having the same issue, any update for this issue?
Then how to get the buffer of the 206 response?