最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Debugging HTML in WebBrowser Control - Stack Overflow

programmeradmin2浏览0评论

I need to embed HTML in a Winforms project and call Javascript functions from it. I'm using a webBrowser control in a c# project and calling:

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

How can I debug execution of code when the debugger is in "myMethod"?

There's this article on how to debug HTML from IE:

I don't know how relevant it is though.

I need to embed HTML in a Winforms project and call Javascript functions from it. I'm using a webBrowser control in a c# project and calling:

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

How can I debug execution of code when the debugger is in "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

I don't know how relevant it is though.

Share Improve this question edited Aug 20, 2012 at 14:23 John Saunders 162k26 gold badges250 silver badges402 bronze badges asked Aug 20, 2012 at 11:09 DavidDavid 16k26 gold badges116 silver badges159 bronze badges 3
  • Have you tried the answer below? – Parag Meshram Commented Aug 21, 2012 at 8:59
  • @ParagM I get "Source code not found" when I try this solution. – David Commented Aug 23, 2012 at 19:32
  • Can you please specify in detail on which code line you are getting this error? If possible please provide a screenshot. – Parag Meshram Commented Aug 24, 2012 at 8:31
Add a comment  | 

2 Answers 2

Reset to default 14

Add following "debugger" line in your website's "myMethod" function -\

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.

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"

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.

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

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

Note: Visual Studio 2019 makes script debugging a little harder to set up and unfortunately no longer supports the Console View/Evaluation window. You can still step and debug value, but no real time evaluation or seeing console.log output.

发布评论

评论列表(0)

  1. 暂无评论