Puppeteer: Could not create typed array
PDF stream conversion did not produce a typed array.
PDF stream conversion did not produce a typed array.
Error message
Could not create typed array
How this error happens
PDF stream conversion completed without producing the byte array Puppeteer expected. 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.