php-chrome-html2pdf: Navigation timeout exceeded error
Hi,
I’m using this wonderful library to print out some labels that are being created in HTML.
We create the HTML and it contains just simple texts and a barcode SVG but nothing too fancy. Some icons are loaded through fontawesome.
// Need to include fontawesome for icons that are used
$labelsHtml .= '<script src="https://kit.fontawesome.com/5084f22b83.js" crossorigin="anonymous"></script>';
and when the HTML is populated we set it like this:
$input = new StringInput();
$input->setHtml($labelsHtml);
$converter = new Converter($input, new EmbedOutput()); $converter->setOptions([
'printBackground' => true,
'landscape' => true,
'width' => $height,
'height' => $width,
'margin' => ['top' => '5mm', 'right' => '5mm', 'bottom' => '5mm', 'left' => '5mm']
]);
$output = $converter->convert();
$output->embed('labels' . DateHelper::now(false, 'd-m-Y-H-i-s') . '.pdf');
We have been using this for quite some time but recently been noticing it takes a lot of time. On the same link we got a timeout earlier today, now it is working, but since fontawesome is loading very fast for me I’m wondering if that is the delay.
Since we set HTML, and there is nothing external except fontawesome, what could be triggering this timeout? Also, is there something we need or can do to speed up the process? Like for example in PHP kill the process or something?
Trying to figure out what might be causing the delay.
Any help is appreciated, see the error below:
Spiritix\Html2Pdf\ConverterException /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php in Spiritix\Html2Pdf\Converter::convert Binary error: node:internal/process/promises:246 triggerUncaughtException(err, true /* fromPromise */); ^ TimeoutError: Navigation timeout of 30000 ms exceeded at /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/LifecycleWatcher.js💯111 at async DOMWorld.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/DOMWorld.js:152:23) at async Page.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:9) at async Converter._convert (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:9) at async Converter.run (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24) at async /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/index.js:23:20 – ASYNC – at Frame. (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:94:19) at Page.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2p…php
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 15 (6 by maintainers)
Indeed, the error isn’t coming from PHP. Will have to investigate this further once I have some time. Meanwhile, I released a new version of the library containing the fix mentioned earlier.
Indeed, puppeteer resp. Chromium in general uses quite a lot of RAM. Increasing memory on the server might make it a bit faster and more stable, but it shouldn’t have such a great impact.
Currently the library doesn’t re-use browser sessions, as it’s request based, like PHP is in general. It’s not optimized for generating a huge bunch of PDF files in a row. This would be a good improvement for the future.