Debugging HTML in WebBrowser Control

I need to embed HTML in a Winforms project and call Javascript functions from it. I use the webBrowser control in a C # project and call:

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

How to debug code execution when the debugger is in "myMethod"?

Here is this article on how to debug HTML from IE: http://www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE

I do not know how relevant this is.

+7
source share
2 answers

Add the following line "debugger" to your site "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; // ... ... } 
Operator

"debugger" will suggest debugging JavaScript.

When myMethod is executed, you will get a hint with which the debugger you want to execute, then from the prompt select "New instance of Visual Studio 2xxx"

Hope this helps.

+13
source

In addition to the approach mentioned by Parag, you can also explicitly enable the debugger in Visual Studio and select the Attach to: Script code .

enter image description here

After that, you will get all open scripts that will be displayed in Visual Studio as Script Documents , and you can set breakpoints in any of these scripts. You can reuse the same instance for multiple debugging sessions. You can also open the JavaScript console and DOM Explorer, which will give you access to the same tools that you get in full Internet Explorer.

enter image description here

More details on the blog here: https://weblog.west-wind.com/posts/2017/Jul/06/JavaScript-Debugging-in-a-Web-Browser-Control-with-Visual-Studio

+1
source

All Articles