TIL the browser will grind your JavaScript to a crawl when the browser window isn’t active.
function sayHi() {
var hi = document.createTextNode(new Date() + " Hi there!\n");
document.getElementById("greetings").appendChild(hi);
}
setInterval(sayHi, 5000);
In my tests, Chrome will call it once a minute, whereas Firefox calls it twice a minute. Both are far away from the 5 seconds I thought I was getting 😃
#javascript #chrome #firefox #webdev
![Showing how the browser executes the `setInterval` method every minute instead of the desired 5 seconds.](https://media.emacs.ch/media_attachments/files/111/521/564/588/628/088/small/ef113da9e6348e2b.png)