3

As do we know, modern browsers stops javascript timers on tab change to improve performance. I found 2 questions from 2011 in about this:

Chrome: timeouts/interval suspended in background tabs?

How can I make setInterval also work when a tab is inactive in Chrome?

Now, 5 years later, I'm trying to force this AngularJS function (based in setTimeout), to work with tab in background, still having no success.

$interval(function(){
  console.log("Test");
}, 100);

Is there any way to get it to work?

Community
  • 1
  • 1
Daniel Campos
  • 971
  • 4
  • 11
  • 20
  • 2
    My immediate answer would be, why? – Wawy Jun 24 '16 at 16:17
  • 2
    I can think of an usecase - to check the inactivity of user and probably log in out of the session after few mins. – Muthukannan Kanniappan Jun 24 '16 at 16:26
  • @Wawy The reason is: I'm developing a delivery system and the back-end must check every 20 seconds if there is a new request from in the database to alert the restaurant with a popup audio. So, every 20 seconds the angularjs send a http request to the back-end, but I need the page to check even if the tab is in background or minimized. – Daniel Campos Jun 24 '16 at 20:06
  • @DanielCampos Have you though about using socket.io for that purpose? – Wawy Jun 25 '16 at 09:48
  • @Wawy I didn't thought about this. It's a good idea. I was reading about Web Workers, is possible to do the same with libs like http://mattslocum.github.io/ng-webworker. What do you think? – Daniel Campos Jun 25 '16 at 18:40

0 Answers0