0

With Chrome Intensive Throttling Chained Timers in Chrome Tabs are suspended after Chrome tab is idle for 5 minutes. https://developer.chrome.com/blog/timer-throttling-in-chrome-88/

I have an application that sends a periodic ping via a websocket to maintain the websocket health. But when the tab becomes idle the periodic pings will be suspended and the backend assumes the connection is disconnected.

I have used setTimeout function in a recursive manner to send the periodic ping. (cancelling the previous timeout and scheduling a new setTimeout periodically) But chrome detects this as a chained timer and suspends the timer.

dilan.sp
  • 41
  • 1
  • 6
  • Does this answer your question? [How can I make setInterval also work when a tab is inactive in Chrome?](https://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome) – Ouroborus Jun 20 '21 at 10:46
  • Why not do the inverse and send a disconnection signal in onunload? You could still add a crazy big timeout to handle the rare cases like disconnection from "I pulled the power cable off", and would save trees by avoiding running a full JS context for nothing more than saying "I'm still alive". – Kaiido Jun 20 '21 at 12:02
  • Finally i used webworkers to schedule timers. Webworker will postMessage to Application in timer events. – dilan.sp Jul 05 '21 at 06:01
  • @Kaiido in my application if i send a disconnection my data will be lost and i need to re-query data from backend. In a network disconnection it is ok. But when tab is idle, it will introduce some discontinuity to the user. – dilan.sp Jul 05 '21 at 06:05
  • @Ouroborus I got the webworker idea from that. Thanks. – dilan.sp Jul 05 '21 at 06:06

0 Answers0