Is there a way to enable the IE8 Developer Tools from inside WebBrowser control in a .NET application

后端 未结 5 1767
青春惊慌失措
青春惊慌失措 2021-02-12 11:22

If you have IE8, you may have noticed a really handy feature that MS has added. Hit F12 and Developer Tools, a firebug like debugger, pops up. This is extremely useful for debug

相关标签:
5条回答
  • 2021-02-12 11:38

    No, as others have said this is not possible. However there is a way you can wire most of the window errors through to a custom handler. Once the document has finished loading you can attach a listener to the window. e.g.

    webBrowser.DocumentCompleted += (o, e) =>
    {
        webBrowser.Document.Window.Error += (w, we) =>
        {
            we.Handled = true;
    
            // Do something with the error...
            Debug.WriteLine(
                string.Format(
                   "Error: {1}\nline: {0}\nurl: {2}",
                   we.LineNumber, //#0
                   we.Description, //#1
                   we.Url));  //#2
        };
    };
    
    0 讨论(0)
  • 2021-02-12 11:44

    Not an ideal solution, but you can use Visual Studio to attach and debug your app in Script mode. You shouldn't debugging the application and / or launch another instance of Visual Studio:

    • DEBUG > Attach To Process ...
    • Attach to must be Script and select your running instance of the application
    • And finally Attach
    0 讨论(0)
  • 2021-02-12 11:45

    I believe the developer tools are implemented in the IE host (iexplore.exe), not in MSHTML itself. Obviously the hooks are there for it, but I don't think you can get to the UI and stuff from the control.

    0 讨论(0)
  • 2021-02-12 11:50

    There isn't a way for the embedded hosts to use the built-in developer tools. But if you want to debug you should still be able to, you can attach visual studio / windbg to your app, at worse you could insert breakpoints with the "debugger" keyword. In VS you might have to select script from the "select..." menu under "debug these code types".

    0 讨论(0)
  • 2021-02-12 11:53

    One option is to open a child window from the embedded page, the child window opens in IE and the Developer Tools work, you can then do

    window.opener
    

    in the console to refer to the parent and manipulate the page.

    Or replace the parents console with the child's and redirect to it.

     var logWindow = window.open();
            logWindow.document.write('<html><head><title>Child Log Window</title></head>\x3Cscript>window.opener.console = console;\x3C/script><body><h1>Child Log Window</h1></body></html>');
            window.onunload = function () {
                if (logWindow && !logWindow.closed) {
                    logWindow.close();
                }
            };
    
    0 讨论(0)
提交回复
热议问题