2

Start function then switch to another window->any timeouts which have < 1 sec rounds to 1 sec

Maybe you will give me some magic?

 [jsfiddle.net/c2dcu045/1/][1]

Edit: https://github.com/turuslan/HackTimer Solved problem , thx to NineBerry

  • Can you give a runnable example in jFiddle or Stack Overflow's code snippet tool and add it to your question? – Hack-R Oct 09 '16 at 00:07
  • timeout and interval aren't meant to be highly accurate - and all browsers I use will decrease this accuracy to the extent you've observed (if not even more) when the page is not in focus – Jaromanda X Oct 09 '16 at 00:13
  • updated https://jsfiddle.net/c2dcu045/1/ – Ибрагим Зубаилов Oct 09 '16 at 00:13
  • Possible duplicate of [How can I make setInterval also work when a tab is inactive in Chrome?](http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome) – NineBerry Oct 09 '16 at 00:33

1 Answers1

1

Mozilla documentation says:

To reduce the load (and associated battery usage) from background tabs, timeouts are often clamped to firing no more often than once per second (1000 ms) in inactive tabs.

Firefox implements this behavior since version 5 (see bug 633421, the 1000ms constant can be tweaked through the dom.min_background_timeout_value preference). Chrome implements this behavior since version 11 (crbug.com/66078).

Firefox for Android uses a timeout value of 15 minutes for background tabs since bug 736602 in Firefox 14, and background tabs can also be unloaded entirely.

It then goes on to say that this is only disabled for tabs with audio playback active. Generally, the time you specify when calling setTimeout, is not guaranteed to be respected by the browser 100%.

Why would having the callback function being called with a slower frequency be a problem for your application?

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • `with audio playback active` - I believe with the current version of firefox, it doesn't even have to be active - but this is a temporary workaround some bug regarding audio, so don't expect to create a dummy audio context and have your intervals/timeouts behave forever :p – Jaromanda X Oct 09 '16 at 00:15
  • cause have a sound play , and user will understand is any happening by this sound ( roulet sounds )(its alltime can be another by timeout); – Ибрагим Зубаилов Oct 09 '16 at 00:17
  • Related: http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome and http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs – NineBerry Oct 09 '16 at 00:30