Halting runaway JavaScript

There are several reasons for needing to stop JavaScript code which is currently running on a page. One reason is when the code is stuck in a loop, doing the same thing around and around forever, causing the browser to freeze. Another reason is if the script is displaying a lengthy or indefinite amount of message boxes, often a prank. Such pranks unfortunately generally necessitate one to kill the browser and lose all open pages and any work therein.

Infinite loops

In the case of the former problem, iCab will display a dialog box after a short while, suggesting that the code is in an "infinite loop", asking whether you want to halt it. An "infinite loop" is where the code is stuck in a loop that will last forever (or when the Sun goes supernova, whichever is sooner) if not forcibly stopped. It can be caused by a defective page, or by a fault in dealing with the JavaScript code on the page. With iCab 2, it is quite often the fault of iCab.

Quite how long it takes for this dialog box to appear is defined in the JavaScript settings in the Preferences. For iCab 3 users on slower machines, the dialog box can take far longer to appear than the time given in the settings, anything up to five minutes or more. At this point, you may decide whether you believe the site is broken, or simply really slow. Fancy drop-down menus, for example, can take a very long time to appear in iCab 3, so while you may receive a warning message, the site is in fact functioning normally.

Something to bear in mind is that you do get more than one chance to stop the code. If you want to let the page run for a bit longer in case you feel it needs to, just choose to not stop it, and iCab will ask you again after the same period of time as before. iCab will in fact never stop asking you, until either the code completes its task, or you finally choose to stop it.

Note that pressing command-. (command-period) to cancel scripts running on the current page will not work; the only option is to wait for the aforementioned dialog box to appear even if it does take a while.

Prank sites and endless message boxes

In the second case, although the script might be running in an infinite loop (keep displaying annoying messages forever), the fact that you are seeing dialog boxes causes iCab to believe that the script is running normally.

To stop a script which is displaying a long or endless sequence of message boxes on the screen, press command-shift-J when one of the dialog boxes is visible, and when you dismiss the box, iCab will terminate the script. (Command is the key with the Apple logo on, immediately to the left of the space bar.)

-- DanielBeardsmore - 20 Oct 2006

Topic revision: r1 - 2006-10-20 - DanielBeardsmore
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback