100

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'});
Philipp M
  • 3,306
  • 5
  • 36
  • 90

7 Answers7

135

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.

James Gould
  • 4,492
  • 2
  • 27
  • 50
70

#UPDATE 2019 (still working 2022)

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

page.setDefaultNavigationTimeout(0); 

The param is the timeout in milliseconds.

References: https://pptr.dev/api/puppeteer.page.setdefaultnavigationtimeout

Juanmabs22
  • 1,194
  • 9
  • 10
39

There are two methods to handle the timeouts in Puppeteer:

a) page.setDefaultNavigationTimeout(timeoutInMiliseconds)

It affects the navigation-related functions:

•   page.goBack([options])
•   page.goForward([options])
•   page.goto(url[, options])
•   page.reload([options])
•   page.setContent(html[, options])
•   page.waitForNavigation([options])

b) page.setDefaultTimeout(timeoutInMiliseconds)

It affects all the previous navigation functions plus all the Waiting funtions:

•   page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]])
•   page.waitForFunction(pageFunction[, options[, ...args]])
•   page.waitForRequest(urlOrPredicate[, options])
•   page.waitForResponse(urlOrPredicate[, options])
•   page.waitForSelector(selector[, options])
•   page.waitForXPath(xpath[, options])

NOTE: page.setDefaultNavigationTimeout takes priority over page.setDefaultTimeout

gnerkus
  • 11,357
  • 6
  • 47
  • 71
Juanma Menendez
  • 17,253
  • 7
  • 59
  • 56
11

You can set timeout like this

await page.goto('url'+tableCell04Val, {waitUntil: 'load', timeout: 10000}).then(() => {
    console.log('success')
}).catch((res) => {
    console.log('fails', res)
})
Henry
  • 1,077
  • 1
  • 16
  • 41
8
await page.goto('url'+tableCell04Val, {  waitUntil: 'networkidle2',timeout: 0});

networkidle2 comes handy for pages that do long-polling or any other side activity.

Check https://github.com/puppeteer/puppeteer/issues/1552#issuecomment-350954419

Rexben
  • 339
  • 4
  • 13
8

The default in puppeteer timeout is 30 seconds. To use custom timeouts, you can use the setDefaultNavigationTimeout and setDefaultTimeout methods or the timeout property in the options parameter. The wait time in all cases is specified in milliseconds.

await page.setDefaultNavigationTimeout(60000);

e.g.

const page = await browser.newPage();            
await page.setDefaultNavigationTimeout(60000); //timeout 60 seconds now

Pass 0 to disable the timeout

await page.setDefaultNavigationTimeout(0); 
-2

I got same error but not on directly using node.js application. I faced this issue when I was using MagePack installed on the Ubuntu server.

I fixed it by increasing the timeout in the following file /ur/local/lib/node_modules/magepack/node_modules/puppeteer/libTimeoutSettings.js

const DEFAULT_TIMEOUT = 30000

Note: It may not be perfect solution but it worked for me and fixed the issue which I was facing.

Mukesh
  • 7,630
  • 21
  • 105
  • 159
  • this is not a solution ... If the job is greater than the previous than it will agains say timeout – Ali Yar Khan Feb 01 '22 at 11:46
  • @AliYarKhan It may not be a proper solution but it worked in my case. – Mukesh Feb 01 '22 at 11:49
  • What happens when you reinstall the project in a different environment? You'd lose the hack. It's difficult to maintain such a code base. – andromeda May 26 '22 at 14:32
  • @andromeda I have already mentioned that it may not be a perfect solution but works for me. The node js is installed on the server and there is a Php application which uses a part of it for deployment process. All better solutions are welcome by me. – Mukesh May 27 '22 at 07:11