Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome / Javascript SetTimeout stuck after computer goes to sleep

I will try to explain ours problem the simpliest possible way. We are facing a tricky bug with our web application + chrome.

We have a web page displaying curves, the refresh of the curve is triggered by a setTimeout. If the computer goes to sleep and then wake up it looks like the setTimeout is not restarting. We have to press our "real time" button to relaunch the setTimeout and then it restarts properly.

Is there a way to fix this issue and to make the refresh of the page active when waking up from sleep ?

Update: We have 6 Chrome instances that display different curves. All auto-refreshing. We leave it for the night. In the morning, waking the computer up from sleep mode and all windows are here, no freeze but no refresh anymore. We have to press our "real time" button on each screen to restart the refresh.

like image 767
Arnaud Avatar asked Nov 10 '22 22:11

Arnaud


1 Answers

Check if the focus event of the whole window or document is triggered when computer comes back from sleep. If its triggered reset your timers from those handlers.

if (/*@cc_on!@*/false) { // check for Internet Explorer
    document.onfocusin = onFocus;
    document.onfocusout = onBlur;
} else {
    window.onfocus = onFocus;
    window.onblur = onBlur;
}
like image 182
sabithpocker Avatar answered Nov 14 '22 22:11

sabithpocker