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. 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"
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. So, if you're using something like $(function () { ... }); Firebug will not be able to access Functions and variables.
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.
Hope that helps.
Does Firebug show the code in the Script tab with green line numbers? 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. Debugging JavaScript in VS just works. It hits breakpoints ("debugger") without a problem and stops all other JavaScript code on the page from executing. So I use it as a back-up quite often.
I have experienced this problem when trying to debug pages within frames using 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 the 'Console' tab on Firebug show errors for any of your other 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.
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.
I had a <script>
tag like this:
<!-- 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.
<!-- 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. It makes sense.
Finally I can see those blessed green numbers.
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.
So, if this is happening to you: check the console, maybe there's a syntax error short-circuiting the loading of the file.
For me it worked after I removed every document.write()
calls.
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.
I resolved it by extracting JS from the page and moving it into its own JS file.
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. So ended up debugging in FB from a separate file, but reverted to inline for production.
I had this problem too. Perhaps related to KIT-Inwi's answer... But I was generating random lines using PHP with each page load.
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".
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.
来源:https://stackoverflow.com/questions/651404/firebug-breakpoint-doesnt-hit