I have a chrome extension that scrolls to the bottom of a users page in order to load all their items (the site uses lazy load)
function makeProgressCountingAllItems() {
// start off by counting all the items you see on the page
allItems = document.getElementsByClassName('items');
// scroll the last item currently loaded
allItems[allItems.length - 1].scrollIntoView();
document.dispatchEvent(new MouseEvent('scroll'));
}
I then want to get all the items on the page (including the newly loaded ones) and put them in an array
function selectItems() {
return document.getElementsByClassName('items')
}
But if I call both of these functions like this
makeProgressCountingAllItems();
selectItems();
The problem is my selectItems function runs before the makeProgressCountingAllItems function gets a chance to scroll to the bottom of the page.
How do I run the second function after the first function is complete?