简体   繁体   中英

How to debug (only) JavaScript in Visual Studio?

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 .

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. :)

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

在此输入图像描述

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. 在此输入图像描述

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM