views:

434

answers:

6

We have an ASP.NET application and when running on client site they often get null reference Javascript errors. As with all these errors the information IE6 displays is less than helpful. But the problem is as soon as I install IE script debugger and try and debug a bit more the error becomes non-reproducible.When script debugger is not installed then the error occurs again. Are there any other tools that could be helpful for javascript debugging on client site. The error is also not produced with IE7 or Firefox.

A: 

Heisenbugs really suck. I agree with jsight that the bugs are likely caused by some race condition; i.e. you're attempting to access elements of the page that don't exist yet.

Edward Z. Yang
I agree it sounds like a race condition. Just hard to find.
Craig
+6  A: 

Do you at least know what object is null? Do you know what line?

If not, you could start by commenting out code until the problem goes away. Then start bringing it back piecemeal until the problem shows up again

alert() is your friend. Try/catch -- with alerts for exceptions -- can be your friend too.

Loading it up with firebug in firefox might help -- even if there's no error displayed by firefox, firebug may give you some useful data especially if you can narrow down the line or object that's having the problem. In the same vein, IE script debugger could give you some useful information even if the error doesn't occur.

Is the code obfuscated? Does the problem occur when it's not obfuscated?

Can you copy the source into a local file and play with the code without involving the server? It'll speed up experimentation, which you're going to be doing lots of.

Moishe
A: 

Do you hve Visual Studio installed?

If so, turn on script debugging in IE like you would for the script debugger.

Add a line to your javascript like...

debugger;

then run your page. You should see a dialog asking you to start debugging. Choose a new instance of VS and walk through the code to see where the error is occuring.

Greg B
A: 

Have you tried Firebug Lite? It gives you lots of Firebug's features via a bookmarklet. I'm not sure it will help with the scripting errors themselves but it will let you browse the loaded scripts and DOM.

Companion.JS may also prove helpful as it gives you slightly better script debugging assistance than IE does.

Odilon Redo
+1  A: 

Check your code with jslint - IE6 often trips up over minor syntax errors that Firefox forgives.

Ken
Every answer to every JavaScript debugging question should start with the above. "If your code does not validate with JSLint, come back when it does."
Kent Brewster
+1  A: 

For anyone that cares, I found the problem. It was a bug in .NET that conflicted with ASP.NET Ajax. It was fixed in .NET 2.0 sp1 which it turns out wasn't installed but so soon as I installed it all problems went away.

Craig