Let's say I have this function:
function test () {
// statements 1
statement_X;
// statements 2
}
I'm stepping trough the statements with the browser's dev tools. Now, when I'm paused at "statement_X", I would like to terminate the function execution (I don't want the "statements 2" part of the function to be executed), as if the "statement_X" is immediately followed by a return;
statement.
I know that Chrome has inline script editing, so I could manually add the return statement after the paused statement and then hit CTRL+S to re-execute the entire thing, but I need this feature for IE too, so I am hoping for a general solution.
Terminating execution early seems like an easy enough thing to do (for the browser), so I expect such a functionality from the dev tools.
Open Chrome DevTools. Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.
Open the Sources panel in Developer Tools ( Ctrl + Shift + I **). Click the Pause button to Pause script execution.
TL;DR Right click in the area where you'd normally set breakpoints, select “never pause here” and you can prevent the debugger from stopping on exceptions or debugger statements.
Call debug(functionName) , where functionName is the function you want to debug, when you want to pause whenever a specific function is called. You can insert debug() into your code (like a console. log() statement) or call it from the DevTools Console.
I tested this successfully in IE 9, so I'm posting it here as an answer: while pausing at statement_X
in the script debugger, hit F10 so statement_X
is still executed, then right click on the last line of the enclosing function (the line with the right curly bracket }
that terminates the function body), and select "Set next statement" from the drop down menu. This will skip execution until the end of the function as if there were a void return statement just after statement_X
.
If there are any other statements on the last line of a function as shown in the code below, be careful to right click just on the curly bracket for this technique to work.
function test () { alert("statement 1");
alert("statement 2"); } function test2 () { alert("statement 3"); }
This may be sometimes necessary in the case of inline functions, or in minified scripts not intended for debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With