简体   繁体   English

如何在Visual Studio中调试(仅)JavaScript?

[英]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. 我正在使用Microsoft Visual Studio 2012开发一个webapplication(asp.net mvc 4),随着解决方案越来越大,调试变得越来越慢。

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). 需要知道是否有一种方法只能在visual studio而不是整个应用程序(服务器+客户端)上调试我的客户端(javascript)。

Is there any way to attach to process of IE and get the breakpoints working ....? 有没有办法附加到IE的进程,让断点工作....?

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. 首先打开Visual studio ..在解决方案资源管理器中选择你的项目。右键单击并选择“浏览方式”选项,然后将IE设置为默认浏览器。

在此输入图像描述 Now open IE ..go to 现在打开IE ..来
Tools >> Internet option >> Advance>> uncheck the checkbox having "Disable Script Debugging (Internet Explorer). and then click Apply and OK and you are done .. Tools >> Internet option >> Advance>> uncheck the checkbox having "Disable Script Debugging (Internet Explorer).然后单击“ Apply ,然后单击“ OK完成。

Now you can set breakpoints in your JS file and then hit the debug button in VS.. 现在您可以在JS文件中设置断点,然后点击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. 编辑: -对于asp.net Web应用程序,右键单击您的启动页面(例如default.aspx)并执行相同的步骤。 :) :)

Yes you can put the break-point on client side page in Visual studio 是的,您可以将断点放在Visual Studio的客户端页面上

First Put the debugger in java-script code and run the page in browser 首先将调试器放在java脚本代码中并在浏览器中运行该页面

debugger 调试器

在此输入图像描述

After that open your page in browser and view the inspect element you see the following view 之后在浏览器中打开页面并查看inspect元素,您会看到以下视图

在此输入图像描述

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. 调试器应该使用Visual Studio 2012自动连接到浏览器。您可以使用debugger关键字在应用程序中的某个点停止或直接在VS中使用breakpoints

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. 您还可以在Visual Studio中分离默认调试器,并使用预装了Internet Explorer或FireBug等的开发人员工具。

To do this goto Visual Studio -> Debug -> Detatch All and then click Start debugging in Internet Explorer . 为此,请转到Visual Studio - > Debug - > Detatch All ,然后单击“在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. 可以通过将关键字“debugger”写入要调试的位置进行调试,只需按F5键即可调试JavaScript代码。

http://www.aspsnippets.com/Articles/Debug-JavaScript-and-jQuery-using-Visual-Studio-in-Internet-Explorer-browser.aspx 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 要在VS2015中调试JavaScript代码,不需要

  1. Enabling script debugging in IE Options -> Advanced tab 在IE选项 - >高级选项卡中启用脚本调试
  2. Writing debugger statement in JavaScript code 在JavaScript代码中编写调试器语句

Attaching IE didn't work, but here is a workaround. 附加IE无法正常工作,但这是一种解决方法。

Select IE 选择IE

在此输入图像描述

and press F5. 然后按F5。 This will attach both worker process and IE as shown here- 这将附加工作进程和IE,如下所示 - 在此输入图像描述

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. 当您按F5并且所有服务器代码在VS中编译并加载时,您仍将面临缓慢的问题。 Note that you can detach and attach again the IE instance launched from VS. 请注意,您可以再次分离并附加从VS启动的IE实例。 JavaScript breakpoints are hit the same way they are in server side code. JavaScript断点的命中方式与服务器端代码相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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