Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When paused on a statement within the browser's dev tools, how to terminate execution immediately after that statement?

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.

enter image description here

like image 450
Šime Vidas Avatar asked Apr 19 '12 14:04

Šime Vidas


People also ask

How do I stop browser execution?

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.

How do I stop chrome from execution?

Open the Sources panel in Developer Tools ( Ctrl + Shift + I **). Click the Pause button to Pause script execution.

How do I stop paused debugging?

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.

What keyword can we put in our code to pause its execution and instantly launch the developer console?

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.


1 Answers

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.

like image 195
GOTO 0 Avatar answered Oct 21 '22 23:10

GOTO 0