Skip to content

Instantly share code, notes, and snippets.

@vadimstasiev
Created July 28, 2020 21:11
Show Gist options
  • Save vadimstasiev/e404570558ad8f0a9be453f48f0612e9 to your computer and use it in GitHub Desktop.
Save vadimstasiev/e404570558ad8f0a9be453f48f0612e9 to your computer and use it in GitHub Desktop.
Fast Infinite Scroll Down - JavaScript
// I made this to use for selenium to inject and get a page to fully scroll down to the bottom
// however as I later found out, certain website elements unload once they get out of the user's view
// but this may come in handy for other things, so here it is
window.isDoneScrolling = false;
let numberOfTries = 0;
const maxNumberOfTries = 100;
let lastScrollHeight = document.body.scrollHeight;
let scrollThePageInterval = setInterval(()=>{window.scrollTo(0, document.body.scrollHeight);
if(lastScrollHeight===document.body.scrollHeight){
numberOfTries+=1;
} else {
lastScrollHeight = document.body.scrollHeight;
}
if(numberOfTries> maxNumberOfTries){
clearInterval(scrollThePageInterval);
console.log("done");
window.isDoneScrolling = true;
}
}, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment