simulate schrool event puppeter code example

Example 1: simulate schrool event puppeter

const autoScroll = async (page) => {
  await page.evaluate(async () => {
    await new Promise((resolve, reject) => {
      let totalHeight = 0
      let distance = 100
      let timer = setInterval(() => {
        let scrollHeight = document.body.scrollHeight
        window.scrollBy(0, distance)
        totalHeight += distance
        if(totalHeight >= scrollHeight){
          clearInterval(timer)
          resolve()
        }
      }, 100)
    })
  })
}

Example 2: simulate schrool event puppeter

page.evaluate(_ => {
  window.scrollBy(0, window.innerHeight);
});

Example 3: simulate schrool event puppeter

window.scrollBy(0, document.body.scrollHeight);