Blog

Tip: Debugging JavaScript using Visual Studio


by Tobias Lekman, 22 May, 2010

Short tip. How to enable breakpoints and step-through debugging using IE and Visual Studio.

I find this very useful for debugging those pesky long SharePoint client script files.

You need to first enable script debugging in your browser (list quoted from MSDN):

  1. In Internet Explorer, click the Tools menu and choose Internet Options.
  2. Click the Advanced tab.
  3. Under the Browsing category, clear the Disable Script Debugging checkbox

Then add the reserved keyword debugger. This keyword indicates where Script Debugger stops execution and starts the debugger. You can use this keyword to trace the values of variables throughout the remainder of the routine. Add this either in your script or, as I prefer to do, on the element using the IE developer toolbar.

image

Clicking the button above will now cause Visual Studio to enter debug mode in step-through from that breakpoint.

 image

For more info, see

http://support.microsoft.com/kb/816173