Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

wait for setTImeout in page.evaluate puppeteer

I am using this code

  await new Promise((resolve, reject) => {
    var list = [1, 2, 3, 4];
    for (var x = 0, ln = list.length; x < ln; x++) {
      setTimeout(async () => {
        console.log('scrolling');
        await page.evaluate(() => {
          window.scrollBy(0, window.innerHeight);
        });
      }, x * 2000);
    }
    resolve();
  });

how do I resolve when all the setTimeouts are over?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of setTimeout, you can use the built-in function of puppeteer:

await page.waitForTimeout(x * 2000);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading