Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telling Firebug to Break as Soon as any Javascript is Executed

I've inherited a pile of code that's doing unexpected things when I click on some <button> elements.

The page has a lot of Javascript, and it's unclear what, if any, events have been setup on the button or its parent elements. I'm trying to find where execution starts so I can debug what's going on.

Is there a way to have Firebug (or any Javascript debugger) break whenever any javascript code is executed? Maybe someway to setup a break point on each line programmatically? Or is there some other way to find out which event the button is responding to (page users boh Prototype, jQuery, and some custom Javascript. I know.)

like image 827
Alan Storm Avatar asked Dec 21 '09 05:12

Alan Storm


People also ask

How to Set a breakpoint in Firefox?

You can set an unconditional breakpoint using the context menu (see above), or by: Clicking on the line number for the line you want to break at in the source pane. Highlighting the line you want to break at in the source pane and pressing Ctrl + B (Windows/Linux) or Cmd + B (macOS).

What does step out do in debugging?

Step Out continues running code and suspends execution when the current function returns. The debugger skips through the current function.

What does step over do in Javascript?

(Step Over) — This instructs the debugger to proceed until the next line of code, but if it encounters a new function, to “step over” it by executing it all in one step. The end result is the execution is paused at the next line of ...


2 Answers

Just press Pause button on the firebug panel (on the left-top corner of it, two yellow vertical lines, when Script tab selected) - and it will stops at first JS string.

But it will stop JS executing really at ANY event - so if you have a button which catches mouse move and mouse click - i will not be able to stop on mouse click, since script will be stopped at mouse move each time you try to move mouse over this button. I suggest you just to insert alert()'s in the suspicious places - after some iterations you will found exactly string you need (where error occurs).

like image 189
user224564 Avatar answered Oct 12 '22 23:10

user224564


Close the Internet browser and open it again. "Break on next" will start working again. Otherwise Firebug simply ignores this option after a while, and doesn´t break but run javascripts for all events without warning you.

like image 40
derloopkat Avatar answered Oct 13 '22 00:10

derloopkat