1 <html> 2 <head> 3 <script> 4 function log(m) { 5 document.getElementById("log").innerHTML += m + "<br>"; 6 } 7 8 var multiplyFactor = 2; // Create this many timers in every timer callback. 9 var targetLatency = 10000; // Multiply timers until it takes this much to fire all their callbacks. 10 var timerCount = 1; 11 12 function timerCallback(creationTimestamp) { 13 --timerCount; 14 15 if (!multiplyFactor) { 16 if (timerCount == 0) 17 log("No more timers - UI should be responsive now."); 18 return; 19 } 20 21 // Create more timers. Capture the current time so when callbacks are fired, 22 // we can check how long it actually took (latency caused by a long timer queue). 23 var timestamp = new Date().getTime(); 24 for (i = 0; i < multiplyFactor; ++i) { 25 setTimeout(function() { timerCallback(timestamp); }, 0); 26 ++timerCount; 27 } 28 29 // Once the timer queue gets long enough for the timer firing latency to be over the limit, 30 // stop multplying them and keep the number of timers constant. 31 if (multiplyFactor > 1 && new Date().getTime() - creationTimestamp > targetLatency) 32 multiplyFactor = 1; 33 } 34 35 function runTest() { 36 log("Freezing UI..."); 37 setTimeout(function() { timerCallback(new Date().getTime()); }, 0); 38 setTimeout("multiplyFactor = 0; log('Finishing. Started to drain timers.');", 10000); 39 } 40 41 </script> 42 </head> 43 <body onload="runTest()"> 44 This test will create enough timers to freeze browser UI. After 10 seconds, it 45 will start drain the timers so the UI becomes responsive again in a few seconds. 46 You don't need to kill the browser.<br>If the bug is fixed, there will be no 47 UI freeze. Refresh the page to repeat the experiment.<br>Try to click at this 48 button (or browser's menu) while UI is frozen: <button onclick="log('clicked')">Click Me</button> <hr> 49 <div id="log"></div> 50 </body> 51 </html> 52