I am creating a Chrome extension that, while on a Udemy course page, checks all the videos, so the certificate will become available, but I am encountering a problem where I activate the click event on all the needed buttons, but this happens so fast that my console gets spammed with net::ERR_INSUFFICIENT_RESOURCES, and only half of all the buttons get clicked and send the POST request to the Udemy servers. Now I was looking for a sleep() function, and a google search told me there isn't one in javascript.
This is the code I am using.
function clickButtons() {
var buttons = document.getElementsByClassName("curriculum-item--progress--3eKMJ btn btn-default")
for (i = 0; i < buttons.length; i++) {
clickButton(buttons, i)
}
}
function clickButton(buttonsArray, index){
buttonsArray[index].click();
}
clickButtons();
If theres another way to circumvent this issue, that would also be appreciated.