调试引发alert()的JS代码 [英] debug JS code which triggers an alert()
问题描述
我正在尝试调试JS代码以查看在什么情况下出现错误信息,即为什么突然出现。我试图用FireBug这样做。有没有人可以使用任何提示来实现我的目标,即建立什么代码行触发alert()?
任何关于此事的输入都非常感谢。
Firebug具有以编程方式创建断点的命令行API。例如:
debug(fn);
为函数 fn
创建一个断点。不幸的是,这不能用于具有本地代码的功能(内置函数,如 alert
)。但是,您可以使用这个技巧。
使用此脚本在代码中插入脚本块 -
window.alert_ = window.alert;
window.alert = function(){
alert_.apply(window,arguments)
};
你所做的是用你自己的window.alert来重新定义一样的事情。 / p>
现在在firebug中附加断点:
debug(alert) ;
下一次脚本调用alert时,您将在函数中获取断点。然后,您可以分析堆栈跟踪并找出从哪里调用。
I have a system which is built using the ext-js library. Part of the system lists orders that are flowing through an online store. When a row is clicked, additional order details are shown. A few days back, a message saying "FIXME: created panelID..." began to appear as soon as a row is clicked. After that, normal functioning continues, i.e. the error message is just annoying and doesn't break normal execution after it appears.
I am trying to debug the JS code to see under what circumstances does the error message appear, i.e. why did it suddenly start appearing. I am trying to do this with FireBug. Does anyone have any tips I could use to achieve my goal of establishing what line of code triggers the alert()? Any input on the matter is much appreciated.
Firebug has a command line API to programmatically create breakpoints. For example:
debug(fn);
creates a breakpoint to the function fn
. Unfortunately this can't be used for functions with native code (built-in functions like alert
). However, you can use this trick.
Insert a script block in your code with this script-
window.alert_ = window.alert;
window.alert = function() {
alert_.apply(window,arguments)
};
What you've done is to redefine window.alert with your own which does the same thing.
Now attach the breakpoint in firebug with:
debug(alert);
Now the next time a script calls alert, you will get a breakpoint in your function. You can then analyze the stack trace and find out where it is getting called from.
这篇关于调试引发alert()的JS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!