Minimum delay setInterval () / setTimeout () on background tabs

Possible duplicate:
Chrome: timeouts / interval paused on background tabs?

Is there a minimum allowable delay for setInterval() and setTimeout() when starting on a tab that you are not looking at right now?

This code runs setInterval() with a specified delay of 100 ms and records how long the delay has been. It also reports when you enter / leave the tab.

 <html> <body> <script type="text/javascript"> window.onfocus = function () { document.body.innerHTML += 'entered tab<br />'; }; window.onblur = function () { document.body.innerHTML += 'left tab<br />'; }; var previous = new Date().getTime(); setInterval(function () { var now = new Date().getTime(); var elapsed = now - previous; document.body.innerHTML += elapsed + '<br />'; previous = now; }, 100); </script> </body> </html> 

Here's an excerpt from the output on Chrome 12.0.742.100 on Ubuntu 10.04.2 LTS:

 101 101 101 left tab 1001 1000 1004 1003 1002 1000 entered tab 101 101 101 102 101 

I also tried different values ​​for the delay. Any value less than 1000 leads to the same behavior that it increases to 1000 when you look at another tab. Values ​​greater than 1000 behave correctly. The same thing happens with the setTimeout() version of this code.

+3
source share
1 answer

I know that your example was for Chrome, but for Firefox, at least from the Firefox 5 release notes (in the "What's New in Firefox" section).

Background tabs have setTimeout and setInterval clamped up to 1000 ms to improve performance


Oh, and I just realized that this has already been set in relation to chrome, here: Chrome: timeouts / interval paused on background tabs? . There is a link that shows that this is also true in Chrome.

+8
source

Source: https://habr.com/ru/post/899707/


All Articles