I have a custom javascript extension that solves a survey on a website. Unfortunately, it works a little too well - it checks the check box and hits next too fast. The website detects this, realizes it's a bot that's solving the survey, and sends an Error, saying that there's too many requests. What code can I use to slow down my extension that won't stop the website?
I've specifically tried to use a sleep() function that I wrote myself which basically stalls the javascript program entirely. I just write a quick "sleep(1500)" before the checkBox method. This actually ends up stopping the javascript on the entire page, which is the exact opposite of what I want.
function sleep(delay) {
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
I'm aiming to have the extension wait roughly 3 to 4 seconds before checking the box and hitting next, after which, it'll wait another 3 to 4 seconds, etc. The actual thing that happens is that before the fancy animation for the checkboxes that the webpage has finishes, the extension's already checked the right box and has hit next. As stated, this is way too fast. Basically, I want to stall the extension for 3 seconds, while letting the javascript on the webpage continue working.