Skip to content

Instantly share code, notes, and snippets.

@jgontrum
Created March 6, 2021 11:07
Show Gist options
  • Save jgontrum/9268bb279dbdb17785ec29d754659fb5 to your computer and use it in GitHub Desktop.
Save jgontrum/9268bb279dbdb17785ec29d754659fb5 to your computer and use it in GitHub Desktop.
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