7

Having used the standard WinForms WebBrowser control in the past, I was able to get OLECMDID_SHOWSCRIPTERROR notifications whenever a script error occurs inside the currently loaded page of the hosted web browser control.

Now I'm switching to use Chromium Embedded (through the CefSharp .NET wrapper) and look for something similar.

I could think of injecting some JavaScript code, but really would love to have a solution that does not require to alter the HTML at all.

My question:

Is it somehow possible that Chromium Embedded notifies my application when a JavaScript error occurs in the current loaded page?

(I'm also asking this in the CefSharp group ant think that this might be independent so asking it here on Stack Overflow, too)

Update 1:

I see that there seems to be an OnUncaughtException function that currently seems to not be implemented by CefSharp. Not sure whether this is about JavaScript errors or CEF errors, though.

Community
  • 1
  • 1
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

6

Although it does not give you the specificity of explicitly knowing when something is an error, you can bind to the ConsoleMessage event. I use this in conjunction with Log4Net to keep track of all console messages from Chromium, which includes most javascript errors:

var webView = new WebView(startUrl, browserSettings);
webView.ConsoleMessage += (sender, args) =>
                                        {
                                log.Debug(string.Format("Webview {0}({1}): {2}", 
                                                                   args.Source, 
                                                                   args.Line, 
                                                                   args.Message))
                                         };
jstromwick
  • 1,206
  • 13
  • 22