Search code examples
apify

How can I wait for ajax completed after click button in puppeteer crawler?


Example:

await page.evaluate(() => {
    $.ajax()...
});

Then, I will get all elements on the page to continue to crawl.


Solution

  • you can use evaluate callback as an async function, like this:

    await page.evaluate(async () => {
        const result = await $.ajax({
        });
    
        // do something with result here
    });
    

    the outer await on page.evaluate will then wait for the ajax to finish before continuing