views:

204

answers:

5

I want to debug a javascript file that is embedded in the HEAD element.

I navigate to the site, see the code, and make a breakpoint:

alt text

But when I click on Reload, the script disappears and it doesn't stop at the breakpoint:

alt text

Debugging was working earlier so I know it works in general. What do I have to do so that Firebug always debugs my script?

+2  A: 

I'm not sure that having a <script> inside <head> (as opposed to, inside <body>) is actually legal HTML. If it's not, as I suspect, you can't fault Firebug for not supporting it well...!-)

Alex Martelli
Having `<script>` in the HEAD is perfectly legal.
webdestroya
seems to make a difference, don't know if this is part of the sometimes-works-issue but at least it is working again now #gettingtoknowfirebug
Edward Tanguay
I don't know of any differences in how Firebug will work with tags in head or body, doesn't matter.
johnjbarton
+1  A: 

I've noticed this behaviour before as well. It seems that it can happen if you refresh the page while the debugger is running (i.e. after you've hit your breakpoint and are stepping through code). This is far from conclusive, just something I've casually observed over time.

Also, I try to avoid having multiple tabs open with firebug active, as it seems to get confused.

Edit: just thought I'd add that I've seen this manifest itself in a few different ways:

  • the external script file does not appear at all in the scripts panel.

  • the external script file appears but firebug doesn't "see" it. You know this has happened because the line numbers beside the code where a breakpoint can be set won't be highlighted (used to be green but now appear to be just a darker shade than other lines). I've seen this happen with inline javascript on a HTML page (horrors!) as well.

  • the external script file is there, but you can only see a single screen full of code. Where "screen full" is the firebug panel viewport.
mmacaulay
JS debugging on multiple tabs is buggy, I should just prevent it.
johnjbarton
A: 

I had the same problem except I had my embedded script inside the body, so that solution didn't work for me. Simply, restarting the browser did the trick.

keyser_sozay
A: 

The bugs in script processing that I know about are 1) jquery dynamic loading of scripts fails, 2) new Function() cannot be seen, 3) some kinds of document.write() cannot be seen.

Firebug processes script files in series with Firefox. This means that Firebug must be active when the page loads and it means that any exception in the path will cause the files to be mis-processed. If you opened firebug before loading and you still see problems, then the most likely fix is to install Firebug in a new Firefox profile. This causes you to get a completely fresh set of default options and you run Firebug without other extensions. As you re-add other extensions, look for problems in seeing scripts: then maybe you will discover what extension is interfering with the code path for processing scripts. I know this is a pain in the neck, but so is JS debugging without source ;-). We are working on testing with more Firebug and Firefox extensions installed to try to reduce these problems.

johnjbarton
A: 

shut down firefox and then restart. sometimes firebug gets confused. also make sure you have the latest version.

Scott Evernden