Skip to content Skip to sidebar Skip to footer

How To Wait For Event Triggered Page Reloads With Puppeteer?

I'm trying safely handle the behavior of a page which uses an in-browser event on a select element to trigger a page reload (POST). The URL is the same but the page reloads with th

Solution 1:

There may be a race condition between selecting and navigation promises (see examples here or here). Can you try this approach?

awaitPromise.all([
  page.select('select[name=sort]', 'size'),
  page.waitForNavigation(),
]);

await page.waitForSelector('select[name=sort]');

Solution 2:

Try page.waitForNavigation.

Quoting from puppeteer docs:

This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly cause the page to navigate.

It seems good for your use case where you are indirectly reloading the page

Post a Comment for "How To Wait For Event Triggered Page Reloads With Puppeteer?"