How to terminate script execution when debugging in Google Chrome?

后端 未结 11 1169
傲寒
傲寒 2020-12-07 08:16

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 browse

11条回答
  •  爱一瞬间的悲伤
    2020-12-07 09:05

    If you are encountering this while using the debugger statement,

    debugger;
    

    ... then I think the page will continue running forever until the js runtime yields, or the next break. Assuming you're in break-on-error mode (the pause-icon toggle), you can ensure a break happens by instead doing something like:

    debugger;throw 1;
    

    or maybe call a non-existent function:

    debugger;z();
    

    (Of course this doesn't help if you are trying to step through functions, though perhaps you could dynamically add in a throw 1 or z() or somesuch in the Sources panel, ctrl-S to save, and then ctrl-R to refresh... this may however skip one breakpoint, but may work if you're in a loop.)

    If you are doing a loop and expect to trigger the debugger statement again, you could just type throw 1 instead.

    throw 1;
    

    Then when you hit ctrl-R, the next throw will be hit, and the page will refresh.

    (tested with Chrome v38, circa Apr 2017)

提交回复
热议问题