简体   繁体   English

在WebBrowser控件中调试HTML

[英]Debugging HTML in WebBrowser Control

I need to embed HTML in a Winforms project and call Javascript functions from it. 我需要在Winforms项目中嵌入HTML并从中调用Javascript函数。 I'm using a webBrowser control in ac# project and calling: 我在ac#项目中使用webBrowser控件并调用:

webBrowser.Navigate("website");
return webBrowser.Document.InvokeScript("myMethod", new object[]{"test"});

How can I debug execution of code when the debugger is in "myMethod"? 当调试器在“myMethod”中时,如何调试代码的执行?

There's this article on how to debug HTML from IE: http://www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE 这篇文章是关于如何从IE调试HTML的: http//www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE

I don't know how relevant it is though. 我不知道它有多相关。

Add following "debugger" line in your website's "myMethod" function -\\ 在您网站的“myMethod”功能中添加以下“调试器”行 - \\

function myMethod(arg1, arg2)
{
    // when myMethod executes you will get prompt that with which 
     // debugger you want to execute
    // then from prompt select "New Instance of Visual Studio 2xxx"
    debugger; 

    //
    ...
    ...
}

"debugger" statement will prompt for debugging the JavaScript. “debugger”语句将提示调试JavaScript。

When myMethod executes you will get prompt that with which debugger you want to execute then from prompt select "New Instance of Visual Studio 2xxx" 当myMethod执行时,您将获得提示您要执行哪个调试器然后从提示选择“Visual Studio 2xxx的新实例”

Hope this will help. 希望这会有所帮助。

In addition to the approach mentioned by Parag, you can also explicitly attach a debugger in Visual Studio and select Attach to: Script code . 除了Parag提到的方法之外,您还可以在Visual Studio中显式附加调试器,并选择Attach to:Script code

在此输入图像描述

Once that's done you get all open scripts to show up in Visual Studio as Script Documents and you can set breakpoints in any of those scripts. 完成后,您将所有打开的脚本作为脚本文档显示在Visual Studio中,您可以在任何脚本中设置断点。 You can reuse the same instance for multiple debugging sessions. 您可以为多个调试会话重用相同的实例。 You also can open a JavaScript Console and DOM Explorer which gives you access to the same tools you'd get in full Internet Explorer. 您还可以打开JavaScript控制台和DOM资源管理器,它可以访问您在完整Internet Explorer中获得的相同工具。

在此输入图像描述

More detail in a blog post here: https://weblog.west-wind.com/posts/2017/Jul/06/JavaScript-Debugging-in-a-Web-Browser-Control-with-Visual-Studio 更多细节在这里的博客文章: https//weblog.west-wind.com/posts/2017/Jul/06/JavaScript-Debugging-in-a-Web-Browser-Control-with-Visual-Studio

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

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