Puppeteer "TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded" when running from Crontab

Viewed 3885

I have a Node.JS automation which uses Puppeteer and loads some URLs as part of the process. My code is pretty basic and uses just the very basic functions as documented in the package documentation.

The automation is scheduled to run with crontab every 15 minutes, but for some reasons run after run I am facing a TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded Error and the page is not loaded successfully. When I run the exact same code manually everything works well and the page load pretty fast.

Can someone think of anything that can the reason for this strange behavior?

Thanks

2 Answers

You can add an option page.setDefaultNavigationTimeout(0) after puppeteer.launch().

    const browser = await puppeteer.launch()
    const page = await browser.newPage()

    page.setDefaultNavigationTimeout(0)

Hope this works fine.

Found the problem, cron processes starts with very basic env variables. Some variables that were necessary for the code were missing, what made the problem.

Related