简体   繁体   English

Firebug - 断点没有击中

[英]Firebug - Breakpoint doesn't hit

I am setting breakpoints in an external JS file and I haven't been able to get Firebug hit the breakpoint in a consistent way. 我在外部JS文件中设置断点,但我无法让Firebug以一致的方式点击断点。 It works sometimes but most of the times it doesn't. 它有时有效,但大多数情况下它没有。 The only way I can get it to work is by switching on "Break on all errors" 我能让它工作的唯一方法是打开“Break on all errors”

I have used the debugger; 我用过调试器; statement as well without any luck. 声明也没有任何运气。

If the line numbers aren't green, it seems like Firebug cannot debug that part of code because it is out of scope. 如果行号不是绿色,似乎Firebug无法调试该部分代码,因为它超出了范围。 So, if you're using something like $(function () { ... }); 所以,如果你使用像$(function(){...})这样的东西; Firebug will not be able to access Functions and variables. Firebug将无法访问函数和变量。

Does that make sense? 那有意义吗?

Also, is it possible that some other function or something is overriding the one you're trying to debug. 此外,是否有可能某些其他功能或某些内容覆盖了您正在尝试调试的功能。 It's even possible if you're including the same JS file twice. 如果你两次包含相同的JS文件,甚至可能。

Hope that helps. 希望有所帮助。

I have experienced this problem when trying to debug pages within frames using Firebug 1.4. 尝试使用Firebug 1.4在帧内调试页面时遇到此问题。 Selecting "Show only this frame" or "Open frame in new tab" from the "This frame" context menu then refreshing the page seems to make the scripts debuggable. 从“此框架”上下文菜单中选择“仅显示此框架”或“在新选项卡中打开框架”,然后刷新页面似乎使脚本可调试。

Does Firebug show the code in the Script tab with green line numbers? Firebug是否在“脚本”选项卡中显示带绿线编号的代码? This indicates debuggable lines of code. 这表示可调试的代码行。

I've experienced this symptom where none of the line numbers were green at times. 我经历过这种症状,其中没有一个行号有时是绿色的。 I refresh the page and magically, they're green again. 我刷新页面,神奇地再次变绿了。

I'm having this problem very often too. 我也经常遇到这个问题。 I've found out that reopening the tab seems to help (the breakpoints are not lost). 我发现重新打开选项卡似乎有所帮助(断点不会丢失)。 But "Break on all errors" looks to be the most reliable way for breaking. 但“打破所有错误”似乎是最可靠的破解方式。

I rarely have to something good about IE, but in this case it gets it right. 我很少对IE有所了解,但在这种情况下,它是正确的。 Debugging JavaScript in VS just works. 在VS中调试JavaScript只是起作用。 It hits breakpoints ("debugger") without a problem and stops all other JavaScript code on the page from executing. 它可以毫无问题地命中断点(“调试器”),并阻止页面上的所有其他JavaScript代码执行。 So I use it as a back-up quite often. 所以我经常使用它作为备份。

Does the 'Console' tab on Firebug show errors for any of your other JavaScript? Firebug上的“控制台”标签是否显示任何其他JavaScript的错误? I found that if JavaScript errors exist for code prior to a debug breakpoint then it will never reach that line of code until the preceding broken one(s) are fixed. 我发现,如果调试断点之前的代码存在JavaScript错误,那么在修复前面的断开代码之前,它将永远不会到达该行代码。

I was having this problem intermittently as well. 我间歇性地遇到这个问题。 I selected "disable all breakpoints" and the "enable all breakpoints" from the breakpoints drop down and it started working. 我选择了“禁用所有断点”并从断点下拉“启用所有断点”并开始工作。

I spent 1 hour on this. 我花了1个小时。

I had a <script> tag like this: 我有一个像这样的<script>标签:

<!-- jQuery Validate -->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js" type="text/javascript">

Can you spot the problem? 你能发现问题吗?

Well it took me all that time to spot it. 好吧,我花了所有时间来发现它。 There's a missing / to close the <script> tag. 缺少/关闭<script>标记。

<!-- jQuery Validate -->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js" type="text/javascript" />

This is for sure due to some copy/paste and then trying to change the code... I just played the fool in this case! 这肯定是由于一些复制/粘贴,然后尝试更改代码...我只是在这种情况下扮演傻瓜! :) :)

After adding the / I was able to get the breakpoints working in Firebug. 添加/我能够在Firebug中使用断点。 It makes sense. 这说得通。

Finally I can see those blessed green numbers. 最后,我可以看到那些有福的绿色数字。

对我来说,删除每个document.write()调用后它都有效。

Same problem with FF 36 and FB 2.0.8: no errors in the console, the code works fine, but FB displays HTML instead of JS, stops at debugger breakpoint but shows it at some random HTML line, does not stop at the regular breakpoints. 与FF 36和FB 2.0.8相同的问题:控制台中没有错误,代码工作正常,但FB显示HTML而不是JS,在debugger断点处停止但在某个随机HTML行显示,不会停在常规断点处。

I resolved it by extracting JS from the page and moving it into its own JS file. 我通过从页面中提取JS并将其移动到自己的JS文件中来解决它。

But there was a catch: when the script resided in its own JS file, I could not get the "global" variables to work in FF (worked fine in IE regardless of where the code was), even using window.varName syntax. 但有一个问题:当脚本存在于自己的JS文件中时,我无法使“全局”变量在FF中工作(无论代码在何处,都可以在IE中正常工作),甚至使用window.varName语法。 So ended up debugging in FB from a separate file, but reverted to inline for production. 因此最终在FB中从单独的文件进行调试,但是还原为内联生产。

I had this problem too. 我也有这个问题。 Perhaps related to KIT-Inwi's answer... But I was generating random lines using PHP with each page load. 也许与KIT-Inwi的答案有关......但是我在每次加载页面时使用PHP生成随机行。

Firebug seems to remember the line number of the entire HTML page to put the breakpoint at, not necessarily the line of the Javascript, which means that the line number you put the breakpoint at on this page load won't necessarily be the same line of code next time you load it, so the breakpoint will appear to "jump". Firebug似乎记得将断点放在整个HTML页面行号 ,不一定是Javascript的行,这意味着你在这个页面上加载断点的行号不一定是同一行代码下次加载时,断点将显示为“跳转”。

I'm not sure how you'd resolve it with dynamic content that changes each time, but I fixed it by removing the random lines so the line with the breakpoint was the same on every page load. 我不确定如何使用每次更改的动态内容来解决它,但我通过删除随机行来修复它,因此每个页面加载时断点的行都是相同的。

Just to add another possibility to those mentioned. 只是为那些提到的人增加另一种可能性。

This one occurred when I was under pressure to fix something in production, naturally. 当我在压力下自然而然地在生产中修理某些东西时,就发生了这种情况。

I had inadvertantely introduced a syntax error: 我无意中引入了语法错误:

function: myFunc(){}

// function body

}

Just like that. 就像那样。 At the beginning of the console log there was an error, but I didn't notice it. 在控制台日志的开头有一个错误,但我没有注意到它。 I kept trying to debug that file, but Firebug wouldn't step into it. 我一直在尝试调试该文件,但Firebug不会介入它。

So, if this is happening to you: check the console, maybe there's a syntax error short-circuiting the loading of the file. 所以,如果发生这种情况:检查控制台,可能会出现语法错误,导致文件加载短路。

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

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