I am building a web app where we have a definition of session length and when the user exceeds the length we have to show a timeout popup to the user.
Currently I have a periodic timer which runs every second checking the remaining time of the session and when it hits the desired value a callback is executed. However recently got to know about the Inactive Tab throttling scenario where the running of timers is indeterministic and may not run at all for tabs in background.
Question: Once the window is brought back into focus, will the timer run again or once it hangs up, the timer does not resume again?
If the timer runs again from what time will it start to run? Are the tick events buffered in a queue or not thrown at all when the tab is in the background.
Any documentation for this would be extremely helpful.
I tried reproducing this in various ways but the results were indeterministic.
setTimeoutandsetIntervalare throttled in inactive tabs, but resumed normally when a tab is activated. Use dates to find the timeout:Also when the timeout happens on an active tabs you can send a message to inactive tabs immediately through
localStorageorBroadcastChannelso the inactive tabs could stop their timers.