Created
March 6, 2021 11:07
-
-
Save jgontrum/9268bb279dbdb17785ec29d754659fb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async autoScroll(page: Page) { | |
await page.evaluate(async () => { | |
await new Promise((resolve, reject) => { | |
let totalHeight = 0; | |
const distance = 500; | |
const timer = setInterval(() => { | |
const scrollHeight = document.body.scrollHeight; | |
window.scrollBy(0, distance); | |
totalHeight += distance; | |
if (totalHeight >= scrollHeight) { | |
clearInterval(timer); | |
resolve(); | |
} | |
}, 200); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment