Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging HTML in WebBrowser Control

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.

like image 486
David Avatar asked Aug 20 '12 11:08

David


People also ask

How do I debug HTML from a website?

Debugging with the Google Chrome Browser The Sources panel is where you debug JavaScript. To open DevTools, press Command + Option + I (Mac), Control + Shift + I (Windows, Linux), or F12. This shortcut opens the Console panel. We will look at the debugger in more detail in the Java Script chapter.

Can you debug HTML?

HTML itself doesn't suffer from syntax errors because browsers parse it permissively, meaning that the page still displays even if there are syntax errors. Browsers have built-in rules to state how to interpret incorrectly written markup, so you'll get something running, even if it is not what you expected.

How do I debug HTML in Chrome?

If you want to debug it, you should press F12 on Chrome to open the developer mode. You can see that the JS code of the current page is under the Source menu, you can set a breakpoint directly at the beginning of the script. Then you can click on the UI button or menu to start debugging(both js and backend activity ).

How do you debug a HTML script?

Start debugging Set the breakpoints in the JavaScript code, as required. Open the HTML file that references the JavaScript to debug or select the HTML file in the Project tool window. From the context menu of the editor or the selection, choose Debug <HTML_file_name>.

Is it possible to debug an embedded web browser control?

Debugging an embedded Web Browser control in a Windows application can be a pain. The Web Browser control is essentially an embedded instance of the Internet Explorer engine, but it lacks any of the support (F12) tooling for debugging.

How do I debug a web browser script?

There are two ways to do this: You can start up Visual Studio and attach a debugger to an already running application that hosts the Web Browser control and specify you want to debug Script code. This works, but it's a bit tedious because you need to explicitly attach the debugger to a running process to do it.

Why can't I debug the Internet Explorer web browser?

The reason: The tools are part of the Internet Explorer Shell host container, not the actual Web browser instance. There's no built in debugging support in the actual Web Browser control itself.

What is missing from the Firebug web browser control?

While full debugging support is a major missing feature for the Web Browser control even with Firebug, the ability to embed console.log commands and get full fidelity state information for objects is immensely valuable.


1 Answers

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.

like image 50
Parag Meshram Avatar answered Sep 22 '22 19:09

Parag Meshram