How to set a interval with Puppeteer to run a certain amount of time?

March 4, 2022 . 1 MIN READ

const puppeteer = require(‘puppeteer’);

(async () => {

let game = ‘https://lichess.org/hj4DgCNN9BKG’;

let browser = await puppeteer.launch({ headless: false });

let page = await browser.newPage();

await page.goto(game, { waitUntil: ‘networkidle2’ });

 

const end = Date.now() + 120000;

 

while (Date.now() < end) {

let data = await page.evaluate(() => {

let time = document.querySelector(‘div[class=”time”]’).innerText;

return { time };

});

console.log(data);

await page.waitForTimeout(1000);

}

})();

Reference: https://stackoverflow.com/questions/66179633/how-to-set-a-interval-with-puppeteer-to-run-a-certain-amount-of-time

Leave a Reply

Your email address will not be published. Required fields are marked *