Feb 10 2007

How to step through Javascript with the Visual Studio debugger

Category: Tips and TricksJoeGeeky @ 21:57

The other day I overheard a conversation related to not being able to “debug” javascript in Visual Studio 2005.  This is a common problem and something that is actually really easy to do.  If you are thinking you don't need this, then think again.  Even if you are not writing Javascript for your projects, open source tools such as the AJAX Control Toolkit and the many third party controls inject javascript at runtime.  From time-to-time these can generate nebulous Javascript errors that can be really hard to trace down.  With that in mind, this is what you do...

In the IE Options Menu, find the option Disable Script Debugging and clear the checkmark next to it.  Assuming you are on a system with Visual Studio 2005 installed, the next time one of your pages generates a javascript error, you will be prompted to start an instance of the VS Debugger and will be able to see the code, step through it, see variable values, etc...

If you have Javascript in your project in the form of a .js file, you will be able to set break points just like you would do in code behind. 

This is really easy, and really powerful so give it a shot and enjoy...  As a side note, leaving Disable Script Debugging disabled can become really obnoxious when you are browsing the web, so you might what to reable it when you don't need it.

Tags: