简体   繁体   English

无法使用Visual Studio 2017或2019调试浏览器JavaScript

[英]Unable to debug browser JavaScript with Visual Studio 2017 or 2019

I am trying to debug a Web app with some ASP.NET (vbhtml) components and some more regular HTML5 bits. 我正在尝试使用一些ASP.NET(vbhtml)组件和一些更常规的HTML5位来调试Web应用程序。 It was built several years ago and makes extensive use of Knockout. 它建于几年前,广泛使用Knockout。 Some of these parts are broken and I am trying to debug them. 其中一些部分已损坏,我正在尝试调试它们。

The project includes an API (WebAPI 2) and some other stuff. 该项目包括API(WebAPI 2)和其他一些东西。 It is not straightforward to separate out the HTML5 parts and debug them using VSCode, so I think I am stuck with using Visual Studio. 分离HTML5部分并使用VSCode调试它们并不简单,所以我认为我坚持使用Visual Studio。

For a tantalizing few minutes two days ago I was able to set breakpoints, step through the Javascript code and find one problem. 对于两天前诱人的几分钟,我能够设置断点,逐步执行Javascript代码并找到一个问题。 I am not sure what I did right. 我不确定我做对了什么。 Since then I have been unable to do any debugging of the Javascript components. 从那时起,我一直无法对Javascript组件进行任何调试。 I have tried using Visual Studio 2017 and 2019. 我尝试过使用Visual Studio 2017和2019。

I ran debugging with Chrome selected and script debugging enabled. 我选择Chrome进行调试并启用脚本调试。 As soon as the browser launched, the breakpoint got a yellow flag at its left hand end which showed a message: The breakpoint will not currently be hit. 一旦浏览器启动,断点在其左端有一个黄色标记,显示一条消息:断点当前不会被命中。 Breakpoint set but not yet bound. 断点设置但尚未绑定。

The browser ran normally but the breakpoint was not hit. 浏览器正常运行但断点没有被击中。 When the Inspect window was open I could see some stuff heppening but nothing relevant. 当Inspect窗口打开时,我可以看到一些东西,但没有任何相关性。

I set up a new "Browse With" entry in Visual Studio. 我在Visual Studio中设置了一个新的“浏览方式”条目。 I selected chrome.exe and added --remote-debugging-port=9222 in the Arguments field. 我选择了chrome.exe并在Arguments字段中添加了--remote-debugging-port = 9222。 Saved it and started debugging. 保存并开始调试。 After the browser opened, I got pop-up error message: Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:51772). 浏览器打开后,我收到弹出错误信息:无法连接到运行时进程,10000毫秒后超时 - (原因:无法连接到目标:连接ECONNREFUSED 127.0.0.1:51772)。

Every time this happens I get a different port number at the end. 每次发生这种情况我都会在最后得到一个不同的端口号。 When I click OK, debugging stops and the browser window closes. 单击“确定”后,调试将停止,浏览器窗口将关闭。 I have made absolutely sure that Chrome is closed before starting debugging, to the extent of running a batch file that kills all Chrome processes. 我已经确保Chrome在开始调试之前已关闭,以及运行批处理所有Chrome进程的批处理文件的程度。

After more searching I selected the Chrome debugging configuration and then Debug|Start Without Debugging. 经过更多搜索后,我选择了Chrome调试配置,然后选择Debug | Start Without Debugging。 Chrome started OK. Chrome启动正常。 I then selected Attach to Process and selected the process. 然后我选择了Attach to Process并选择了该过程。 It all looked good but the breakpoint went inactive again with the "breakpoint will not currently be hit" message. 一切看起来都不错,但断点再次失效,“断点当前不会被击中”的消息。

I have tried adding "debugger;" 我试过添加“调试器”; entries to the code. 代码的条目。 VS 2019 complains about them and they have no effect. VS 2019抱怨他们,他们没有任何效果。

If I try debugging with IE11 and got similar results. 如果我尝试用IE11调试并得到类似的结果。 Sometimes I got an error saying that another debugger was already connected although I had previously killed Chrome. 有时我得到一个错误,说已经连接了另一个调试器,尽管我之前杀了Chrome。

I am at a loss. 我很茫然。 Any clues would much appreciated. 任何线索都会非常感激。

Rob

The problem was definitely in the bundle configuration. 问题肯定在捆绑配置中。 In my case it is a file called BundleConfig.vb. 在我的例子中,它是一个名为BundleConfig.vb的文件。 It appears to bundle up JavaScript and css files to enable faster loading of the site rather than loading each of the files as a discrete HTTP request. 它似乎捆绑了JavaScript和css文件,以加快网站的加载速度,而不是将每个文件作为离散的HTTP请求加载。

My file starts like this: 我的文件开头是这样的:

Imports System.Web.Optimization
Public Module BundleConfig
    ' For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    Public Sub RegisterBundles(ByVal bundles As BundleCollection)
        bundles.Add(New ScriptBundle("~/bundles/jquery").Include(
                   "~/Scripts/jquery-3.4.1.min.js",
                   "~/Scripts/jquery-ui-1.12.1.js"))

and ends like this: 并以此结尾:

       BundleTable.EnableOptimizations = False  'Commented out 190601 to debug scripts
        'BundleTable.EnableOptimizations = True
    End Sub
End Module

If EnableOptimization is True you will not be able to debug any of the JavaScript with either Visual Studio or the debug tools in Chrome or IE. 如果EnableOptimization为True,您将无法使用Visual Studio或Chrome或IE中的调试工具调试任何JavaScript。 Comment it out and debugging becomes possible. 将其注释掉并调试成为可能。

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

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