Saturday, February 25, 2006

JavaScript debugging

After JavaScript debugging with boring alert() and slow Venkman (FireFox extension) I was glad to know that Visual Studio can handle javascripts.

Not only ASP.NET projects can be debugged, but plain HTML + JavaScript sites/pages as well (say - Random Sudoku ;)).

It's pretty easy (not very straightforward though):
1. Be sure Script Debugging in IE is enabled. (Uncheck Disable Script Debugging in Internet Options \ Advanced).
2. Add debugger keyword in your JavaScript. It should be in the function you want to debug.
E.g. if you need to debug Foo() when the keyword in Foo():

Foo = function() {
debugger
var i = 0;
}

If you put debugger outside of Foo() then you will not be able to set breakpoint in there.

3. Start IE, and open your HTML. You'll see Visual Studio Just-In-Time Debugger dialog when debugger keyword is reached.

4. In the dialog choose debugger you wish to use, and enjoy!

Labels: , , , ,

0 Comments:

Post a Comment

<< Home