Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 491
Uwe Keim Avatar asked May 29 '13 11:05

Uwe Keim


People also ask

How to fix Chromium Edge not responding to Windows 10?

To reset the Chromium Edge to its default settings to fix problems, use these steps: Open Microsoft Edge. Click the Settings and more (three-dotted) button from the top-right. Click the Settings option. Click on Reset settings. Click the Restore settings to their default values option.

How to get chromium to show up inside a WinForms application?

Getting Chromium to show up inside a .NET WinForms application is relatively easy using CefSharp. CefSharp is an open source project which provides Embedded Chromium for .NET (WPF & WinForms).

Why does the script fail when H2 element does not exist?

But no h2 element exists, so the script fails. Other errors that the Console reports are network errors. To display it in action, navigate to the Network error reported in Console.

Is there a way to suppress certificate error in edge chromium?

Is there a way to suppress the certificate error in Edge chromium. Please suggest Your antivirus can interfere with Microsoft Edge and cause the mentioned error to appear. So you might want to change its configuration and disable certain settings, or you might want to consider disabling or removing your antivirus completely.


1 Answers

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))
                                         };
like image 123
jstromwick Avatar answered Oct 03 '22 08:10

jstromwick