1

I've been experiencing some strange behavior with a web app I've been working on where the app doesn't function as expected when a user switches tabs. After some googling, I found the comments section on this question: How do browsers pause/change Javascript when tab or window is not active? which indicated that time outs under 1000 ms are increased to 1000ms when page focus is lost. This behavior would explain a lot of quirks that I've seen in my web app where the console.time feature was inexplicably reading out 1000ms times. After searching google I haven't been able to find any articles detailing this behavior and I haven't found a way to prevent it. Does anyone happen to know where I could find more info or how I might prevent chrome from increasing my timeouts on page blur?

EDIT: To answer the useless "Why?" response, it's a WebRTC app that I've been working on as a novelty. If certain timers in my page stop working the app is no longer a web based real time communication app, and is a web based delayed communication app.

Thanks to apsillers for finding the solution to this problem. This link: setTimeout/setInterval 1000ms lag in background tabs (Chrome and Firefox) details how web workers can circumvent this behavior.

Community
  • 1
  • 1
Dan Truitt
  • 107
  • 6
  • 3
    Why? Your application is not really supposed to be doing anything when it isn't shown. This is a fully reasonable CPU-(and power-)saving measure. – Luaan Nov 03 '15 at 13:32
  • The traditional approach is to detect slowed intervals (by logging `new Date()`) and do more. For example, if you normally expect 100ms intervals, and you detect a 1000ms interval, do ten times as much as usual. I'll see if I can find a post that has sample code. – apsillers Nov 03 '15 at 13:32
  • 2
    This might be a duplicate of [setTimeout/setInterval 1000ms lag in background tabs (Chrome and Firefox)](http://stackoverflow.com/questions/19475894/settimeout-setinterval-1000ms-lag-in-background-tabs-chrome-and-firefox) – apsillers Nov 03 '15 at 13:35
  • Thank you, that link looks promising. – Dan Truitt Nov 03 '15 at 13:48
  • Reason you are not using WebSockets? – epascarello Nov 03 '15 at 13:54
  • Mostly for the challenge. – Dan Truitt Nov 03 '15 at 13:57
  • "for the challenge" okay there.... Well other option is to use Web Workers or compile your own version of chrome that removes the timeout increase that has been in the browser for ~5 years – epascarello Nov 03 '15 at 14:02

0 Answers0