Puppeteer: stream is missing from Page.printToPDF
Page.printToPDF did not return the stream expected by createPDFStream.
Page.printToPDF did not return the stream expected by createPDFStream.
Error message
stream is missing from Page.printToPDF
How this error happens
Chrome’s printToPDF result did not include the stream handle requested by Puppeteer’s PDF implementation. This is a browser/protocol or stream-processing failure, not an invalid paper-format setting.
The failing snippet uses an open page in the affected environment. The correction uses an imported puppeteer instance.
await page.pdf({
format: "A4",
});
How to fix
Use a compatible Chrome/CDP page, finish page work before printing, and keep the browser alive until the PDF bytes have been read.
const browser = await puppeteer.launch({
browser: "chrome",
protocol: "cdp",
});
try {
const page = await browser.newPage();
await page.setContent(
"<h1>Report</h1><p>Ready to print.</p>"
);
const pdf = await page.pdf({
format: "A4",
});
console.log(pdf.byteLength);
} finally {
await browser.close();
}
Things to keep in mind
The first PDF call is valid; it only fails when the browser response or stream conversion has the condition described above. A new browser session can isolate a broken connection, but it is not a universal repair for an incompatible browser or Puppeteer bug. Do not fabricate stream IDs.