Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JavaScript breakpoints in Visual Studio 2008 or Visual Studio 2010

I'm trying to debug JavaScript code using Visual Studio 2010, but I can't set breakpoints.

How can I do this?

I just noticed something, every time I try to call a function, no matter what function, in JavaScript, somehow jQuery and Microsoft's Ajax framework JavaScript captures it and checks if the document is ready (document.onready or other) and never returns the control back to the function I'm calling! Why on earth is it doing this? I've never asked for it to!

All I have are references to these libraries, script/link references as you do on the top of your master page.

This is ridiculous, how do I fix it?

like image 324
Erx_VB.NExT.Coder Avatar asked Feb 12 '10 12:02

Erx_VB.NExT.Coder


People also ask

How do I set a breakpoint in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

Can you Debug JavaScript Visual Studio?

The Visual Studio Code editor supports debugging of JavaScript running in Microsoft Edge and Google Chrome. You can read more about debugging browsers works in the Browser Debugging documentation.

Can you use breakpoints in JavaScript?

In the debugger window, you can set breakpoints in the JavaScript code. At each breakpoint, JavaScript will stop executing, and let you examine JavaScript values. After examining values, you can resume the execution of code (typically with a play button).


2 Answers

If your script is in a separate script file (.js), then you can just use F9 to set a breakpoint on a line.

You can't set a breakpoint if the script is incorporated in another file like an aspx file. For cases like that, use the debugger; javascript statement to force a break at a certain spot.

Also make sure that you are working with the latest version of your javascript file, do a Ctrl-F5 in IE if necessary to force a fresh reload of the file.

like image 57
kime waza Avatar answered Sep 18 '22 05:09

kime waza


Use the debugger; statement before the line where you want to stop execution and debug.

Example

var test = "testString";
debugger; // stops execution and can start debugging
test += "newly added";
like image 27
rahul Avatar answered Sep 20 '22 05:09

rahul