0

As part of learning AngularJS, I decided to rewrite Cookie Clicker using it. I have a controller set up and it has (among other things) $scope.Cookies, $scope.CPS (to represent the cookies per second), and an Update function like so:

$scope.Update = function() {
    $scope.Cookies = $scope.Cookies + ($scope.CPS / 100);

    $timeout($scope.Update, 10);
}

While I have the tab up front and center, the Cookie count increases correctly. I've found that if I'm looking at a different tab then this isn't updating.When switch back to my tab, it picks up where it left off. I've tested this by putting the Cookie count in the title bar and confirming that it stops. EDIT: Instead of running 100 times a second, it appears to be running 1 time a minute.

What can I do to ensure the timeout continues to fire at the expected interval?

Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
  • Can you post a fiddle that shows your issue? I've constructed one at http://jsfiddle.net/XGnrU/1/ , but the count seems to update find when the tab isn't in focus. – Michal Charemza Oct 22 '13 at 18:54
  • I updated yours to actually call the update function and for me it exhibits the same stopping behavior. http://jsfiddle.net/XGnrU/2/ – Corey Ogburn Oct 22 '13 at 19:50
  • IE 10 seems to be the only browser of mine where the count continues to increment at a seemingly normal rate. Chrome and Firefox both slow down. – Corey Ogburn Oct 22 '13 at 19:52
  • This feature seems to be by design for chrome (and probably firefox): http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs – Corey Ogburn Oct 22 '13 at 22:24

0 Answers0