Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation timeout exceeded error #35

Open
coxfrederic opened this issue Mar 29, 2022 · 13 comments
Open

Navigation timeout exceeded error #35

coxfrederic opened this issue Mar 29, 2022 · 13 comments
Labels
help wanted Extra attention is needed

Comments

@coxfrederic
Copy link

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:100: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

@spiritix
Copy link
Owner

Hi @coxfrederic,

Generally, "TimeoutError: Navigation timeout of 30000 ms exceeded" means the page took more than 30s to load and render, which is very unlikely. If the page loads fast in a browser, it should also load fast in this library.

You need to make sure that all external URLs in the HTML are accessible from the machine where you execute the library. For example, if you have a script like <script src="http://localhost/my.js"> it could actually end up in the mentioned error, since the external resource couldn't be loaded.

If that doesn't help, you can send the HTML to my email, maybe I can spot something.

@coxfrederic
Copy link
Author

Hi @spiritix ,

Thanks for your quick response.

The memory on the server is limited to 2GB and I found online that Puppeteer needs around 1GB of RAM ? So we increased the memory on the server to see if that improves things.

The external URL we will replace with images instead of using fontawesome.

I see the library is creating a new instance of a browser each time and closes it. Is that the preferred way or is there also an option to re-use the same instance? Would that improve things or actually not?

@spiritix
Copy link
Owner

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.

@coxfrederic
Copy link
Author

Currently our problem seems solved by upgrading RAM, but an option for the library to re-use the same instance for X amount of time would indeed be very nice in some use cases. I'll keep an eye on it and will close this issue for now.

Anyway, awesome work on this library, and thanks for your help!

@coxfrederic
Copy link
Author

I'm reopening this issue since I'm getting the same error for a page that loads a lot of content. In my browser it takes around 65-70 seconds.

I have tried setting the timeout option to 300 seconds but it doesn't have any effect. I'm still getting the TimeoutError: Navigation timeout of 30000 ms exceeded after 30 seconds.

How come the timeout value is not taken into account? Any solution to this problem?

@coxfrederic coxfrederic reopened this Apr 24, 2023
@spiritix
Copy link
Owner

Can you try to open the website directly in Puppeter and convert it to PDF, to see how long it takes to load? Something like this should do it:

const puppeteer = require('puppeteer')
 
async function printPDF() {
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto('https://url.com', {waitUntil: 'networkidle0'});
  const pdf = await page.pdf({ format: 'A4' });
 
  await browser.close();
  return pdf
})

@coxfrederic
Copy link
Author

It takes around 65 seconds to load

@spiritix
Copy link
Owner

@coxfrederic Thanks, this confirms that it's an issue with Puppeter. Maybe this fix helps? puppeteer/puppeteer#1846 (comment)

If so, I can implement it in this library

@coxfrederic
Copy link
Author

Yes! That would be amazing if you could implement it

@coxfrederic
Copy link
Author

What I don't understand though, the timeout is still at 30seconds. So it is ignored?
I don't see how this is related to puppeteer/puppeteer#1846 (comment) that the error fires after 30 seconds even though I specified the timeout to 300 seconds.

@spiritix
Copy link
Owner

Indeed, those issues are not related. I suspect that the timeout is coming from PHP and not from Puppeter, because in PHP the default timeout is also 30 seconds.

@coxfrederic
Copy link
Author

Based on the error I do not believe it is a PHP timeout.

TimeoutError: Navigation timeout of 30000 ms exceeded
at /var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/LifecycleWatcher.js:100:111
at async DOMWorld.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/DOMWorld.js:152:23)
at async Page.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:9)
at async Converter._convert (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:9)
at async Converter.run (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24)
at async /var/puntoo/vendor/spiritix/php-chrome-html2pdf/index.js:23:20
-- ASYNC --
at Frame. (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:94:19)
at Page.setContent (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:46)
at Page. (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:95:27)
at Converter._setHtml (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:88:21)
at Converter._convert (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:20)
at Converter.run (/var/puntoo/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /var/puntoo/vendor/spiritix/php-chrome-html2pdf/index.js:23:20

It is thrown in

public function convert(): OutputInterface
{
$result = ProcessUtil::executeShellCommand($this->buildCommand(), $this->input->getHtml());
if (strpos(mb_strtolower($result['error']), 'error') !== false) {
throw new ConverterException('Binary error: ' . $result['error']);
}

@spiritix
Copy link
Owner

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.

@spiritix spiritix added the help wanted Extra attention is needed label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants