puppeteer icon indicating copy to clipboard operation
puppeteer copied to clipboard

[Bug]: Puppeteer PDF generation via Page.pdf() method

Open GiovaniMFMurari opened this issue 10 months ago • 6 comments

Bug description

I was creating a simple html to pdf converter when I stumbled into a little issue with all the current version of the fork.

In the current implementation of the Page.pdf method in the @cloudflare/puppeteer fork, the Readable stream returned by Page.createPDFStream is converted to a Buffer by the function getReadableAsBuffer in puppeteer src/common /util.ts, where the problem is at. The getReadableAsBuffer function tries to iterate over a non iterable object(node:stream/Readable), what causes an TypeError: readable is not async iterable exception.

It can be easily solved by using Page.createPDFStream directly, but is still an issue which is not present in the @puppeteer/puppeteer-core package.

Steps to reproduce the problem:

  1. Launch puppeteer and instantiate a Page with some content:
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.setContent('<h1>HELLO CLOUDFLARE</h1>', {
waitUntil: 'networkidle0',
});
  1. Get the PDF:
 await page.pdf({ displayHeaderFooter: true })

Below is the link of a repo to reproduce the issue. https://github.com/GiovaniMFMurari/cf-puppeteer-pdf-gen-test

Puppeteer version

0.0.6

Node.js version

16, 18 and 20

npm version

using pnpm 8.15.5

What operating system are you seeing the problem on?

Linux

Relevant log output

✘ [ERROR] Uncaught (in response) TypeError: readable is not async iterable

      at getReadableAsBuffer
      at Page.pdf
      at async Object.fetch
      at async drainBody

GiovaniMFMurari avatar Apr 13 '24 19:04 GiovaniMFMurari