ggrossetie / asciidoctor-web-pdf

Convert AsciiDoc documents to PDF using web technologies
https://asciidoctor.org
MIT License
443 stars 91 forks source link

page.ToPDF timeout error doesn't follow global settings #612

Closed holytrousers closed 2 years ago

holytrousers commented 2 years ago

Hello first of all, i would like to express my gratitude for everybody's work on this project.

Unable to generate the PDF - Error: TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded
> TIP: You can configure the timeout in milliseconds using PUPPETEER_DEFAULT_TIMEOUT, PUPPETEER_NAVIGATION_TIMEOUT or PUPPETEER_RENDERING_TIMEOUT environment variables.

This error happens when a certain number of images is inserted into the document. Setting the appropriate environment variables doesn't help. Looks like the 30s value is hardcoded in this declaration

const { scale = 1, displayHeaderFooter = false, headerTemplate = '', footerTemplate = '', printBackground = false, landscape = false, pageRanges = '', preferCSSPageSize = false, margin = {}, omitBackground = false, timeout = 30000, } = options;

in node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js hope it helps others with fixing the problem Cheers !

ggrossetie commented 2 years ago

We don't specify a timeout when we call Page.pdf(). More than 30 seconds to generate a PDF seems a bit excessive but as you've mentioned maybe Chrome takes a bit of time when the document contains a lot of images.

Anyway, we should declare a new environment variable to configure this timeout: PUPPETEER_PRINT_TIMEOUT.

The "default" timeout only applies to navigation (Page.goto and Page.reload) and rendering (Page.waitForFunction).

holytrousers commented 2 years ago

We don't specify a timeout when we call Page.pdf()

Indeed, the problem was with the misleading 'TIP'.

More than 30 seconds to generate a PDF seems a bit excessive but as you've mentioned maybe Chrome takes a bit of time when the document contains a lot of images.

Actually, the timeout happens when the document exceeds a dozen of pictures ( JPEG files around ~ 3MB size ) These pictures however are inserted in the page layout as running elements positioned inside the margins of the page, which might explain the excessive time. With the --preview option however, chromium renders the page in a couple of seconds.

Anyway, we should declare a new environment variable to configure this timeout: PUPPETEER_PRINT_TIMEOUT.

And a different message for this specific timeout.

The "default" timeout only applies to navigation (Page.goto and Page.reload) and rendering (Page.waitForFunction).

It might be even better to create a separate 'TIP' for each timeout since it actually isolates the problem. Thank you for your help !

ggrossetie commented 2 years ago

Fixed in 643d5548bc9953e592957ccc356162b8523ab672