Debugging JavaScript in a WebBrowser Control from VS2010

You can debug JavaScript executing inside a WebBrowser control embedded in your .NET 4.0 application from VS2010 (Visual Studio 2010), but it takes a little effort.

  1. Enable Script Debugging (both IE and Other) in Internet Explorer.
  2. Disable friendly HTTP messages in Internet Explorer.
  3. Enable Display a notification about every script error in Internet Explorer.
  4. Modify VS2010 to debug Script from the Attach Process dialog. Please note that you cannot debug both JavaScript (Script) and .NET 4.0 code at the same time. (I don't know why.)
  5. Add a debugger; statement at the start of your JavaScript.
  6. Start your WebBrowser-embedded application without debugging (Ctrl-F5).
  7. When your application hits the JavaScript debugger; statement, select your current instance of VS2010.
  8. Voilà! You can now debug the JavaScript executing inside the WebBrowser control in your .NET 4.0 application.

(Posted here so I don't forget the steps.)

(This was abstracted from many sources including Silverlight 4 Tools for Visual Studio 2010 Debugging Overview.)

Leave a comment

About Mark Leighton Fisher

user-pic Perl/CPAN user since 1992.