How to debug (only) JavaScript in Visual Studio?

2019-01-10 22:09发布

问题:

I'm developing a webapplication (asp.net mvc 4) with Microsoft Visual Studio 2012, and as the solution is getting bigger, the debug is getting slower.

Need to know if there is a way to debug only my client side (javascript) on visual studio instead of the entire application (server+client).

Is there any way to attach to process of IE and get the breakpoints working ....?

Not interested on get the debugger running on entire client/server application, just client.

回答1:

First open Visual studio ..select your project in solution explorer..Right click and choose option "browse with" then set IE as default browser.

Now open IE ..go to
Tools >> Internet option >> Advance>> uncheck the checkbox having "Disable Script Debugging (Internet Explorer). and then click Apply and OK and you are done ..

Now you can set breakpoints in your JS file and then hit the debug button in VS..

EDIT:- For asp.net web application right click on the page which is your startup page(say default.aspx) and perform the same steps. :)



回答2:

The debugger should automatically attach to the browser with Visual Studio 2012. You can use the debugger keyword to halt at a certain point in the application or use the breakpoints directly inside VS.

You can also detatch the default debugger in Visual Studio and use the Developer Tools which come pre loaded with Internet Explorer or FireBug etc.

To do this goto Visual Studio -> Debug -> Detatch All and then click Start debugging in Internet Explorer. You can then set breakpoints at this level.



回答3:

Yes you can put the break-point on client side page in Visual studio

First Put the debugger in java-script code and run the page in browser

debugger

After that open your page in browser and view the inspect element you see the following view



回答4:

It is possible to debug by writing key word "debugger" to place where you want to debug and just press F5 key to debug JavaScript code.

http://www.aspsnippets.com/Articles/Debug-JavaScript-and-jQuery-using-Visual-Studio-in-Internet-Explorer-browser.aspx



回答5:

For debugging JavaScript code in VS2015, there is no need for

  1. Enabling script debugging in IE Options -> Advanced tab
  2. Writing debugger statement in JavaScript code

Attaching IE didn't work, but here is a workaround.

Select IE

and press F5. This will attach both worker process and IE as shown here-

If you are not interested in debugging server code, detach it from Processes window.

You will still face the slowness when you press F5 and all your server code compiles and loads up in VS. Note that you can detach and attach again the IE instance launched from VS. JavaScript breakpoints are hit the same way they are in server side code.