Firebug - Breakpoint doesn't hit
Asked Answered
A

11

38

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.

Altheta answered 16/3, 2009 at 17:37 Comment(1)
Does it work in Firefox's built-in debugger?Vitovitoria
F
15

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.

Fungistat answered 16/3, 2009 at 20:50 Comment(1)
Firebug also seems to frequently not realize that code is valid. This seems to occur most often in do while loops: Firebug refuses to green the line numbers, even though it should.Constitution
R
6

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.

Radicalism answered 16/3, 2009 at 17:42 Comment(1)
Nope, refreshing the page doesnt help. They don't have green line numbers as well.Altheta
S
6

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.

Singlehandedly answered 16/3, 2009 at 21:2 Comment(0)
T
6

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.

Thremmatology answered 13/8, 2009 at 1:10 Comment(0)
C
3

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.

Calipee answered 25/8, 2009 at 20:3 Comment(0)
T
3

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.

Tumulus answered 11/8, 2014 at 22:41 Comment(0)
N
2

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.

Norm answered 9/10, 2012 at 4:41 Comment(0)
C
0

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.

Chouinard answered 24/2, 2011 at 21:24 Comment(0)
C
0

For me it worked after I removed every document.write() calls.

Capps answered 23/2, 2015 at 15:19 Comment(0)
M
0

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.

Matrona answered 9/3, 2015 at 17:8 Comment(0)
R
0

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.

Reheat answered 2/5, 2016 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.