I'm building an abstraction/simplification for Puppeteer in Nodejs, to scrape single page applications. One of the basic actions it will perform, is scrolling down a page multiple times, in order to trigger the AJAX call. what i do is basically:
(()=>{
page.on('response', async res => {
if (res.includes('/someAjaxAction')) {
numResponses++
}
})
while(numResponses<20){
await scrollDown();//Calling my function that scrolls down.
await Promise.delay(400)//Creating a delay just in case...
}
})()
I setup the onResponse event listener, and count for the number of times, the appropriate ajax call was performed. I scolldown infinitely, until this condition is met, and that's it - I can use the complete HTML.
The problem is, that this would force the client coder to provide a number of ajax calls they anticipate. What i would like, is to somehow recognize a situation, when no more scrolling is possible. Like: we've reached the end of the page.
Any idea as to how i could abstract such a situation?