简体   繁体   English

使Firebug内部动态加载javascript

[英]Making Firebug break inside dynamically loaded javascript

I'm looking for a way to debug a dynamically loaded jQuery document.ready function. 我正在寻找一种方法来调试动态加载的jQuery document.ready函数。

Obviously I can't just bring up the script panel and add a breakpoint with the mouse since the function does not exist there. 显然我不能只调出脚本面板并用鼠标添加断点,因为那里没有函数。

I've also tried adding "debugger;" 我也试过添加“调试器”; to the function (without the quotes), but that did not do anything. 功能(没有引号),但没有做任何事情。 I have ensured that the function is actually executed while I tried this. 我已经确保在我尝试这个时实际执行了该功能。

Thanks for your help, 谢谢你的帮助,

Adrian 阿德里安

Edit: I just noticed that Firebug actually breaks on debug. 编辑:我刚刚注意到Firebug实际上在调试中断了。 However, when it does so on a dynamically loaded script, it does not bring up the source code of that script as usual. 但是,当它在动态加载的脚本上执行此操作时,它不像往常那样显示该脚本的源代码。 Plus, the call stack ends right below my own code. 另外,调用堆栈在我自己的代码下面结束。 I can bring up the implementation for document.ready via the call stack, but that does not really help. 我可以通过调用堆栈调出document.ready的实现,但这并没有真正帮助。 Is this a Firebug bug or have I missed something? 这是一个Firebug错误还是我错过了什么?

I just worked on this similar question . 我只是在研究这个类似的问题 The solution involves adding the word debugger twice; 解决方案包括两次添加调试器一词; once at the top of the external file and one more time at the top of the function that needs to be debugged. 一次位于外部文件的顶部,另一次位于需要调试的函数顶部。

I noticed that if the debugger word was used only once, it did not work. 我注意到如果调试器单词只使用一次,它就不起作用了。 Example: 例:

//myExternal.js
debugger;
function myExternalFunction(){
 debugger;
 /* do something here */
}

I don't know if you ever got this figured out, but in case someone else needs it... 我不知道你有没有想到这个,但万一其他人需要它...

I got around this by moving the code I wanted to debug to an external file that was linked from the main page. 我通过将我想调试的代码移动到从主页链接的外部文件来解决这个问题。

In my case, I had default.aspx loading services.aspx into a content div using jQuery AJAX. 在我的例子中,我使用jQuery AJAX将default.aspx加载到内容div中。 Services.aspx in turn, was loading jQuery UI tab elements using AJAX from a webservice that was providing it data. 反过来,Services.aspx正在使用AJAX从提供数据的Web服务加载jQuery UI选项卡元素。 The webservice code was in a file called data.js which was linked from default.aspx. Web服务代码位于名为data.js的文件中,该文件是从default.aspx链接的。 I needed to debug the code that was in the header of services.aspx (that loaded the tabs with data), but couldn't ever see it in any of the available inspectors. 我需要调试services.aspx标头中的代码(用数据加载标签),但是在任何可用的检查器中都看不到它。 I just moved the code I needed to a new function in data.js and called it from the header in services.aspx. 我只是将我需要的代码移动到data.js中的一个新函数,并从services.aspx中的头部调用它。

I hope that makes sense to someone who needs it! 我希望对需要它的人有意义!

Just encountered same behavior (Firebug ignoring debugger; statement in dynamically loaded code) in Firefox 5.0/Firebug 1.7.3 . 刚刚遇到Firefox 5.0 / Firebug 1.7.3中的相同行为(Firebug忽略debugger;动态加载代码中的语句)。

Worked around by detaching Firebug window ("Open Firebug in New Window"). 通过分离Firebug窗口(“在新窗口中打开Firebug”)解决了这个问题。

You might try placing a break point where the event is called, and then instead of click "Play", choose "Step Into" (F11). 您可以尝试在调用事件的位置放置一个断点,然后选择“Step Into”(F11),而不是单击“Play”。 I don't have a test case in front of me, but I think this may work. 我面前没有测试用例,但我认为这可行。

There's also a 'debugger' keyword that's supported by the IE JScript debugger, and Safari's Web Inspector, so i would be surprised ifit wasn't supported in firebug. 还有一个'调试器'关键字,IE JScript调试器和Safari的Web Inspector支持,所以如果firebug不支持我会感到惊讶。

Basically: 基本上:

// mydynamicallyloadedfile.js
... // do stuff
debugger; // triggers debugger
... // more stuff

And i would expect firebug to break at the debugger keyword 我希望firebug能够打破debugger关键字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM