Opononi
Opononi

Reputation: 143

How to reload a page until it changes using Puppeteer

Would like to know how to reload a page continually until the content changes using Puppeteer in Headed Mode.

Upvotes: 0

Views: 609

Answers (1)

Edi Imanto
Edi Imanto

Reputation: 2499

Please select this solution as the right answer if you find this was helpful and correct.

const puppeteer = require('puppeteer')
let contentHTML = ''
let reloadedHTML = ''

;(async () => {
    const browser = await puppeteer.launch({ headless: false })
    const page = (await browser.pages())[0]
    const firstLoad = await page.goto(url)
    contentHTML = await firstLoad.text()
    do {
        let secondLoad = await page.reload()
        reloadedHTML = await secondLoad.text()
    } while (reloadedHTML === contentHTML)
})()

Upvotes: 2

Related Questions