Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js puppeteer - How to set navigation timeout?

I'm using node.js and puppeteer to get some data. Some of the files I'm opening are quite large ... and then I get an error:

Error:

our error { TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded     at Promise.then (/project/node_modules/puppeteer/lib/NavigatorWatcher.js:74:21)     at <anonymous> name: 'TimeoutError' } 

How can I ignore it or set a higher timeout?

That's my script:

await page.goto('url'+tableCell04Val, {waitUntil: 'load'}); 
like image 787
Philipp M Avatar asked Sep 04 '18 09:09

Philipp M


People also ask

How do you fix timeout error in puppeteer?

A simple workaround is to override the default timeout value, setting the new value to _0_ and passing a “waitUntil”: “load” parameter in the options object in the Puppeteer goto() method.

Which option should be set to avoid page Getting timeout error in puppeteer?

You can use timeout: 0 to disable timeout errors if you're loading a heavy page. Use it in your page. goto like: await page.


2 Answers

You can use timeout: 0 to disable timeout errors if you're loading a heavy page.

Use it in your page.goto like:

await page.goto('url'+tableCell04Val, {waitUntil: 'load', timeout: 0}); 

You can see the PR made to Pupeteer here which added the change, along with documentation and the unit tests that implement it.

like image 190
James Gould Avatar answered Sep 17 '22 22:09

James Gould


#UPDATE 2019

You can also change the page behaviour since V1.0.0:

page.setDefaultNavigationTimeout(0);  

The param is the timeout in milliseconds.

References: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetdefaultnavigationtimeouttimeout https://pptr.dev/#?product=Puppeteer&version=v1.17.0&show=api-pagesetdefaultnavigationtimeouttimeout

like image 32
Juanmabs22 Avatar answered Sep 16 '22 22:09

Juanmabs22