Puppeteer: Could not load response body for this request. This might happen if the request is a pr...
The response body is unavailable for the protocol request ID; a preflight is one possible case.
The response body is unavailable for the protocol request ID; a preflight is one possible case.
Error message
Could not load response body for this request. This might happen if the request is a pr...
How this error happens
Not every response has a readable body. CORS preflight responses are one example; trying to read all response bodies indiscriminately can hit a missing protocol body.
The snippets use an open Chrome/CDP page named page.
page.on("response", async (response) => {
const body = await response.text();
console.log(body);
});
How to fix
Filter for the response your task actually needs, skip known bodyless cases, and still handle a body-read failure.
page.on("response", async (response) => {
const request = response.request();
if (request.method() === "OPTIONS") {
return;
}
if (response.status() === 204 || response.status() === 304) {
return;
}
try {
const body = await response.text();
console.log(body);
} catch (error) {
console.error(
"Response body unavailable:",
response.url(),
error.message
);
}
});
Things to keep in mind
The failing listener needs traffic with an unavailable body to reproduce the error. Redirects, timing and closed targets can also affect body access. Do not swallow missing data that your application requires.