'How to spam a button on with a while true without crashing with click()

Basically, I tried to do:

while (true) {

document.querySelector("#main \> footer \> div.\_2BU3P.tm2tP.copyable-area \> div \> span:nth-child(2) \> div \> div.\_2lMWa \> div.\_3HQNh.\_1Ae7k \> button").click()

}

but it just crash, how can I make it stable?

I'm expecting to spam the button but without crashing.



Solution 1:[1]

Rather than use a while loop, use setInterval to repeat your code at a reasonable delay. The following code will run your click code every 500ms, for example:

function doClick() {
 // Put your click code here
}

setInterval(doClick, 500);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nate Norris