0

I have a webbrowser control, but when I try to load the page, it shown me a JS errors. If I click "Yes" to all errors, page loading normally and page JavaScript works fine. enter image description here

I tried to set

webBrowser.ScriptErrorsSuppressed = true;

but then JavaScript on the page stop working (as I understood, this call is equals to clicking "No" on all JavaScript errors).

How can I fix this? What shoud I do not to display the page errors and confirm all of them to continues page script ignoring them?

Greg
  • 241
  • 2
  • 4
  • 8
  • 1
    Do you have to use the crappy webbrowser-control based on IE? If not, you could move to https://cefsharp.github.io/ it uses the Chromium engine so you will not get those errors and you will have full HTML5 / CSS3 support and a better performance overall. – Isma Sep 23 '17 at 10:24
  • 2
    [How can I get the WebBrowser control to show modern contents?](https://stackoverflow.com/a/38514446/3110834) – Reza Aghaei Sep 23 '17 at 11:37

2 Answers2

1

maybe you could try following way, first modify browser's documentcomplete event , then set your own error handling procedure, codes like follows

private void webBrowser_Inner_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
 //other code
       ((WebBrowser)sender).Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
// other code
}
private void Window_Error(object sender, HtmlElementErrorEventArgs e)
{     // Ignore the error and suppress the error dialog box.     
    e.Handled = true;
}

I tested success in my browser pages, maybe you can have a try

J1B
  • 178
  • 1
  • 12
0
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler((object s, WebBrowserDocumentCompletedEventArgs e) => {
    ((WebBrowser)s).Document.Window.Error += new HtmlElementErrorEventHandler((object s2, HtmlElementErrorEventArgs e2) => {
        e2.Handled = true;
    });
});

Shorter approach of @J1B's answer

Ma Dude
  • 477
  • 1
  • 5
  • 17