Lor-Saba/Code-Injector

setInterval only runs for 5-6 miliseconds

Opened this issue · 1 comments

Injecting the script

setInterval(console.log('hi'), 1);

only runs approximately 5 times (5 milliseconds) then stops. re-injecting the script has the same effect, but slows down the browser with each injection until the tab is closed.

You could try setInterval(function() {console.log('hi');}, 1);.

The setInterval() function expects a function as the first argument (MDN Reference). When the JS engine sees your code, it evaluates the console.log('hi') expression hoping to get a function. This expression has the side effect of printing 'hi'. Thus it only gets printed once.

You have a delay of 5ms (not 1ms) because of the way concurrency works in JS. Talking about the event loop is off topic, but just keep in mind that you can't have exact sleep timings in JS.