Neskews
Neskews

Reputation: 824

Puppeteer not waiting for timeout

I have a page with a list of company names. This list is initially limited by 200 results, but there is a link to double that limit. With every click the loading time rises up to a few minutes.

I am using following code.

/**
 * @param {object} page - a puppeteer page object
 * @param {number} by - how many times I need to click on the link
 */
async function multiply(page, by = 5) {
    for (let i = 0; i < by; i++) {
        await Promise.all([
            // Manual clicking of the link
            page.$eval('p a', el => el.click()),

            // set a timeout of 8 minutes
            page.waitForNavigation(480000) 
        ]).catch(e => console.log(e));
    }
}

I expect a timeout of 8 minutes, but I get the follwing error:

Error: Navigation Timeout Exceeded: 30000ms exceeded

I have also tried to wait for Navigation before clicking on the link. Then I tried to manually wait for a defined timeout with page.waitFor(i ** 2 * 10000) - but no luck. Waiting for the selector to be in the html did not work either.

I am not using page.click('p a'), because it is confirmed as a bug here.

You may wanna have a look at another already-solved question to my project, which describes my use case little bit more in detail.

If you want to have a closer look, you can clone the complete repo by clicking on bitbucket.org/ytNewskews.

Upvotes: 1

Views: 6887

Answers (1)

Carsten
Carsten

Reputation: 878

page.waitForNavigation(options) expects an Object with properties like this:

   // set a timeout of 8 minutes
   page.waitForNavigation({timeout: 480000})

The default is 30000ms. The default value can be changed by using the page.setDefaultNavigationTimeout(timeout) method.

From: Puppeteer API

Upvotes: 3

Related Questions