admin管理员组文章数量:1193963
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.)
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.)
Share Improve this question edited Dec 21, 2009 at 5:45 o.k.w 25.8k6 gold badges67 silver badges63 bronze badges asked Dec 21, 2009 at 5:39 Alana StormAlana Storm 166k95 gold badges416 silver badges618 bronze badges5 Answers
Reset to default 12Just 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).
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.
I found a bookmarklet that will list all bound events in your page.
This kind be useful if you don't know what events are bound by third-party code.
If you want to see what events are set up on the page, you might also try Eventbug.
If this is a generic debugging problem you can use the Web Inspector in Safari / Chrome. An added bonus is that you can throw the following statement into your JavaScript code to pull up the debugger:
...
debugger; // Will trigger the debugger
...
Otherwise you can set breakpoints, conditional breakpoints, pause on the next execution, and all the usual tricks. Some nice videos are available here.
In response to the alert
suggestion before. I would seriously recommend using console.log
or console.dir
if you have access to a debugger. You will get more information without blocking your script's execution. Also, don't forget that that console.log
can take multiple parameters so you can nicely print out data, you don't have to constrain yourself to a single string like alert
.
本文标签: debuggingTelling Firebug to Break as Soon as any Javascript is ExecutedStack Overflow
版权声明:本文标题:debugging - Telling Firebug to Break as Soon as any Javascript is Executed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738493386a2089838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论