Programmatically stop JavaScript execution in Firebug

35,876

You can use the debugger statement:

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

It works in all major browsers.

Share:
35,876
Admin
Author by

Admin

Updated on February 27, 2020

Comments

  • Admin
    Admin over 4 years

    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 ...
    
  • Kirtan
    Kirtan almost 15 years
    It will also work with IE if you enable Script Debugging in the Internet Options.
  • James Wiseman
    James Wiseman almost 15 years
    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.
  • snapfractalpop
    snapfractalpop over 10 years
    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).
  • JonnyRaa
    JonnyRaa almost 10 years
    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
  • James Dunn
    James Dunn about 9 years
    The debugger directive now works in Opera. (Tested in Opera 28)