How do you interrupt JS in browser?

From what little insight I have into your ways of working, how I would proceed is:

  • Only execute the script on an event like button click. This would prevent script running onload
  • Chrome allows you to set break points in your js code in the scripts tab of developer tools

In Chrome, you can hit Shift+ESC (or right-click the title bar and open the Chrome task manager) and kill the process associated with the hung tab. This will work in cases where closing the tab would not.

The caveat is, sometimes Chrome will streamline several tabs into one process, and this will kill all the tabs associated with the process.


Another approach you can take to avoid while loops hanging the browser is to write code like this (you can take it out after testing):

var maxIterations = 100000; 
while (foo) {
    if (!maxIterations--) throw new Error('Max iterations hit, aborting.');
    // do stuff
}

Right-click in Chrome's task manager and select the item on the bottom of the context menu to reveal a strange easter egg.


There is no such thing as a Ctrl + C for JavaScript. The browsers that executes JavaScript are usually protective of themselves. If any JavaScript hangs, they'll throw a dialog asking if the user wants to stop the JavaScript.

The timeout duration can usually be found in the browser's settings. You can find how to do it for FireFox here: http://kb.mozillazine.org/Dom.max_script_run_time