Thursday, October 12, 2006

Javascript debugger hilites wrong line

You will probably see a lot of JavaScript related posts in this blog,
well, this is because I do lots of JavaScript.

This time I was trying to add FireFox Support to a web app I am working on.
Usually I work with IE and with VS2005 for debugging.

This time I had to do some debugging inside FF,so I tried both venkman and firebug and had the same problem.

I placed a debugger; statement inside a function I wanted to debug (obviously - why else),
and when the debugger came to life it would hilite the line that is two lines above the one containing the debugger; statement.

well for a while I said - well, I will just have to live with it, but after a while I discovered this was easier said then done.

Thinking why this could happen I decided that it must have something to do with the document being changed dynamically and hence the lack of synchronization between the reported lines numbers and the actual displayed code.

so I played with a few simple examples, suppose you have a page that has the following markup:

<script>
s='<div>hello\nworld\n</div>';
document.write(s);
</script>
<script>
function go(){
debugger;
alert('a');
alert('b');
}
</script>
Hello


We would expect it to break at the debugger statement, but see for your self:
Photobucket - Video and Image Hosting
(And no, I did not make it step ahead).

Playing with it for a while I suddenly relized that my original problem was exactly the opposite of this one, as in this case the line that is being hilited is below the actual line being debuged.

so I went to my page, added:
<script type="text/javascript">
document.write('\n\n');
</script>

And voila, debugging became a reasonable task again.

Still the mystery remains - what could cause the debugger to hilite the wrong line but ABOVE the correct line.

Any ideas anyone ?

1 comment:

Tim said...

I have this same problem. I don't think there is any document.write stuff however. It's really annoying. I wish I had an answer, but it's my problem that brings me here.

Firebug needs Debug.

 
Clicky Web Analytics