If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

How does one go about debugging javascript?

If javascript is part of an ASP.NET application, I have found that the breakpoints in a .js file in Visual Studio seem to be ignored.

The problem I see is that the ASP.NET application which uses javascript code has too versions -- a published and a debug version. The Debug version is located within my group of folders under the localhost. Also, when I launch the program through Visual Studio, it defaults to IE. Is there some way I can have it launch a different browser that will allow for javascript debugging?

I'm going to stick my neck out on this one, since I'm not part of that other forum and happen to know the answer.

(1) Don't use FF or IE, if possible. Use Chrome. It's the easiest to use JS debugger. The big failing of the IE debugger is that it can't catch and then tell you about errors that happened before you turned it on, so you have to turn it on and then refresh the page, which means you may have to do many more steps to get to the point of failure again. Ugh.

(2) Don't launch your ASP.NET page from Visual Studio. Bring up Chrome and then type in the URL to the page, even if it's http://localhost/something.aspx
Then hit the F12 key to turn on the debugger. Presto. Easy. I do it all the time.

(3) And if it's not obvious: Don't use Visual Studio as your JS debugger, ever. It worked okay back in ASP.NET version 1.1 days, but the debuggers built into the browsers--even the one in IE--are so much better than VS for debugging JS that it's never worth the hassle.

I use Firefox. Ctrl+Shift+K brings up the error console, Ctrl+Shift+I brings up the generated DOM, and Ctrl+Shift+Q lets you monitor the network. Firefox also has a font inspector.

I also use XAMPP to test files locally, which saves time over constantly uploading the files to a live server.

Originally Posted by glenngv

I also don't like IE dev tools very much but the upcoming IE11 dev tools look very good and maybe even better than Chrome and Firebug.

I have IE11/Windows 8.1 Developer Preview installed. While the tools are a big improvement over IE10, they have some drawbacks. In particular:

The console still only records errors after it's opened and you refresh the page.

The console reports useless things like indicating that an XSLT transformation occurred.

Microsoft removed the compatibility modes switcher for older versions of IE, which, while not entirely accurate, were quicker to use than booting up a virtual machine (which could always be done at the end for further bugfixing). There's a mode field in the options that reflects the state of the document, but you can't change the value.

It still uses F12 key activation, which is annoying because I have to physically look at my keyboard every time I need to use it. I can find shortcuts in Firefox and Chrome (Ctrl+Shift+I/J) without even looking at the keyboard. But that's just a personal thing, I guess.

On the other hand:

You can have the console up while any other developer pane is open, which I don't think any other browser has out of the box.

The UI is large and readable, which I assume is for touch compatibility.

It also has a better Trace tool than Chrome when it comes to determining the font in use. (But Firefox is still better.)

For every complex problem, there is an answer that is clear, simple, and wrong.

(2) Don't launch your ASP.NET page from Visual Studio. Bring up Chrome and then type in the URL to the page, even if it's http://localhost/something.aspx
Then hit the F12 key to turn on the debugger. Presto. Easy. I do it all the time.

In Visual Studio 2012, you can choose which browser to use by default when launching the site. There is a dropdown in the toolbar that lists all the browsers installed. I don't know if previous versions have the same feature.