Issues with window.setInterval in Edge 89

Steffens, Zach 16 Reputation points
2021-03-22T16:33:13.477+00:00

I'm a web developer working on an enterprise app and we rely on window.setInterval.

I noticed some strange behavior in the app seemingly connected to an AngularJS $interval method.
So I began testing the native JS window.setInterval to see if the issue was AngularJS or the underlying native JS.
The issue occurs with the native JS methods as well.

To boil this down the the simplest repeatable example possible, I created a code pen here.

The purpose of this code is to output the time between calls to the setInterval callback function.

window.setInterval((event) => {
  const lastTime = JSON.parse(window.sessionStorage.getItem("lastTime"));
  const thisTime = new Date();
  if (lastTime) {
    const timeDiff = thisTime.getTime() - Date.parse(lastTime);
    console.log("time: " + timeDiff.toString());
  }
  window.sessionStorage.setItem("lastTime", JSON.stringify(thisTime));
}, 30000);

To test the codepen, open a dev tools window, after the first minute, console logs will output the elapsed time between calls to the interval callback function.

When I inject this code into the landing page of my web app (it's a login page) the timer begins to malfunction after 5 to 10 iterations. These aren't slight anomalies, they are off by a factor of 2. Starting at 30 seconds, and then moving to 60seconds

In the included code pen, it functioned properly for the first 55 reports before I saw the first 60000, then it resumed normal timing for the next 100 reports and at report 155 i received 7 in a row that reported 60000 instead of 30000.

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,124 questions
{count} votes