Is it possible to get notifed when hosted Chromium Embedded has a JavaScript error?
Asked Answered
S

1

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.

Swaziland answered 29/5, 2013 at 11:28 Comment(0)
R
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))
                                         };
Retene answered 9/1, 2014 at 22:16 Comment(3)
The ConsoleMessage event isn't raised for errors, at least not all of them. Try hooking window.onerror to pipe the messages to the console first.Gummy
In my Angular app I'm adding an $httpProvider.interceptors to log failed calls in a way that ConsoleMessage will receivePhilology
What is the ConsoleMessage event raised for then?Productive

© 2022 - 2024 — McMap. All rights reserved.