1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function busyLoop(millis) {
6 for (var d = Date.now(); Date.now() - d < millis; ) { }
10 if ("webkitVisibilityState" in document
11 && document.webkitVisibilityState == "hidden")
13 if ("mozVisibilityState" in document
14 && document.mozVisibilityState == "hidden")
16 if ("msVisibilityState" in document
17 && document.msVisibilityState == "hidden")
28 timerId = window.setTimeout(loop, 50);
32 if (visible() && !timerId)
33 timerId = window.setTimeout(loop, 50);
36 document.addEventListener("webkitvisibilitychange", handler, false);
37 document.addEventListener("mozvisibilitychange", handler, false);
38 document.addEventListener("msvisibilitychange", handler, false);