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.
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.
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.
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 ).
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>.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With