question

SteffensZach-8624 avatar image
0 Votes"
SteffensZach-8624 asked YuZhou-MSFT edited

Issues with window.setInterval in Edge 89

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.




ms-edge
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SteffensZach-8624
I saw that you have asked the same question in stackoverflow.
Let's wait to see if there're any other community members have different opinions.

0 Votes 0 ·

0 Answers