How to terminate script execution when debugging in Google Chrome?

When stepping through JavaScript code in Google Chrome debugger, how do I terminate script execution if I do not want to continue? The only way I found is closing the browser window.

Pressing "Reload this page" runs the rest of the code and even submits forms as if pressing F8 "Continue".

UPDATE :

When pressing F5 (Refresh) while a script is paused:

  • Google Chrome (v22) runs the script. If the script submits HTTP request, the HTTP response for that request is displayed. The original page is not refreshed.
  • IE 9 just freezes. However IE has an option "Stop Debugging" which, when pressed (provided you did not press F5 earlier), continues to run the script outside debugger.
  • Firebug behaves identically to Chrome.
  • Closing and then opening again the browser window is not always the next easiest way because it will kill browser session state and that may be important. All your breakpoints are also lost.

    UPDATE (Jan 2014) :

    Refresh while debugging:

  • Chrome v31: lets scripts to run and stops on further breakpoints (but does not submit ajax requests), then refreshes.
  • IE 11: refresh does nothing, but you can press F5 to continue.
  • Firefox v26: lets scripts to run but does not stop on further breakpoints, submits ajax requests, then refreshes.
  • Kind of progress!

    Navigate to the same page while debugging:

  • Chrome v31: same as Refresh.
  • IE 11: scripts are terminated, new browser session is started (same as closing and opening again).
  • Firefox v26: nothing happens.
  • Also juacala suggested an effective workaround. For example, if you are using jQuery, running delete $ from console will stop execution once any jQuery method is encountered. I have tested it in all above browsers and can confirm it is working.

    UPDATE (Mar 2015) :

    Finally, after over 2 years and almost 10K views, the right answer was given by Alexander K. Google Chrome has its own Task Manager which can kill a tab process without closing the tab itself, keeping all the breakpoints and other stuff intact.

    I even went as far as BrowserStack.com to test it in Chrome v22 and found that this was working this way even at that time.

    Juacala's workaround is still useful when debugging in IE or Firefox.


    In Chrome, there is "Task Manager", accessible via Shift+ESC or through

    Menu → More Tools → Task Manager

    You can select your page task and end it by pressing "End Process" button.


    One way you can do it is pause the script, look at what code follows where you are currently stopped, eg:

    var something = somethingElse.blah;
    

    In the console, do the following:

    delete somethingElse;
    

    Then play the script: it will cause a fatal error when it tries to access somethingElse , and the script will die. Voila, you've terminated the script.

    EDIT: Originally, I deleted a variable. That's not good enough. You have to delete a function or an object of which JavaScript attempts to access a property.


    Refering to the answer given by @scottndecker to the following question, chrome now provides a 'disable JavaScript' option under Developer Tools:

  • Vertical ... in upper right
  • Settings
  • And under 'Preferences' go to the 'Debugger' section at the very bottom and select 'Disable JavaScript'
  • Good thing is you can stop and rerun again just by checking/unchecking it.

    链接地址: http://www.djcxy.com/p/91110.html

    上一篇: Google CDN上最新的jQuery版本

    下一篇: 如何在Google Chrome中进行调试时终止脚本执行?