72

I am currently debugging complex JavaScript code with Firebug. I am looking for a way to stop the JavaScript execution as if it was a breakpoint programmatically.

Example:

instructions ...
degugger.breakpoint(); // the execution stops here as if a breakpoint was
                       // manually set
other instructions ...

1 Answer 1

125

You can use the debugger statement:

// your JS code
...
// break here
debugger;

It works in all major browsers.

Sign up to request clarification or add additional context in comments.

5 Comments

It will also work with IE if you enable Script Debugging in the Internet Options.
After you have done this, you should be then be able to use breakpoints in your IDE debugger. This saves you from having to declare multiple 'debugger;' lines of code across your application.
I'm surprised how long I've gone without realizing you could do this. Thanks, this is very helpful. I would add that, for Chromium on Linux, this line of code will only pause execution if the debugger is open (and the disable breakpoints toggle is not selected).
this didn't work for me in firefox. Do you have to have the debugger open? I had firebug open but was looking at the console + network tabs. I wasn't actually interested in the code/state at the time but just wanted the console output to stop
The debugger directive now works in Opera. (Tested in Opera 28)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.