Page 1 of 1

Intercept JS errors ?

Posted: Tue Feb 12, 2019 10:37 am
by thefunkyjoint
Let's say i run a JS code with a syntax error. In which event i can get the error message ? It seems the error does not trigger the 'onConsoleMessage' event.

Re: Intercept JS errors ?

Posted: Tue Feb 12, 2019 11:01 am
by salvadordf
Use the GlobalCEFApp.OnUncaughtException event to catch exceptions globally.

That event is triggered in the render process only and you will need to set GlobalCEFApp.UncaughtExceptionStackSize to a value greater than 0 to enable it.

You can also use the "window.onerror" JavaScript event to catch errors and send them to Delphi with a custom JS extension.

Re: Intercept JS errors ?

Posted: Wed Feb 13, 2019 11:21 am
by thefunkyjoint
salvadordf wrote: Tue Feb 12, 2019 11:01 am Use the GlobalCEFApp.OnUncaughtException event to catch exceptions globally.

That event is triggered in the render process only and you will need to set GlobalCEFApp.UncaughtExceptionStackSize to a value greater than 0 to enable it.
In this case a JS error will throw a Delphi exception ?

Re: Intercept JS errors ?

Posted: Wed Feb 13, 2019 11:39 am
by salvadordf
thefunkyjoint wrote: Wed Feb 13, 2019 11:21 am
salvadordf wrote: Tue Feb 12, 2019 11:01 am Use the GlobalCEFApp.OnUncaughtException event to catch exceptions globally.

That event is triggered in the render process only and you will need to set GlobalCEFApp.UncaughtExceptionStackSize to a value greater than 0 to enable it.
In this case a JS error will throw a Delphi exception ?
No. The JS error will only trigger the GlobalCEFApp.OnUncaughtException event in the render process.

The "OnUncaughtException" name is just the CEF method name for that event but it has nothing to do with Delphi exceptions.

Re: Intercept JS errors ?

Posted: Thu Feb 14, 2019 10:36 am
by thefunkyjoint
Thanks, is there any example on any demo ?

Re: Intercept JS errors ?

Posted: Thu Feb 14, 2019 10:51 am
by salvadordf
I'm afraid not. :oops:

However, it shouldn't be too difficult to extract the information you need from the context, exception and stackTrace parameters.

The API documentation links for those parameters and for ICefV8StackFrame are these : Then you can use the browser parameter to send a message to the main process with the information, like the DOMVisitor demo does :

Code: Select all

browser.SendProcessMessage(PID_BROWSER, msg);

Re: Intercept JS errors ?

Posted: Thu Feb 14, 2019 10:57 am
by salvadordf
I just edited my previous post. In case you read the old version, reload this page.

Re: Intercept JS errors ?

Posted: Tue Oct 15, 2019 4:22 pm
by salvadordf
mmontu wrote: Tue Oct 15, 2019 2:51 pm I have tried UncaughtExceptionStackSize with:

Code: Select all

GlobalCEFApp.UncaughtExceptionStackSize := 10;
GlobalCEFApp.OnUncaughtException := MyAppOnUncaughtException;
but seems that it´s not working. MyAppOnUncaughtException() it´s not being executed. There it´s an example with this feature working or there is some issue and should use Window.onerror?
GlobalCEFApp.OnUncaughtException is executed in the render process. You need to use the debugging techniques described here :
https://www.briskbard.com/index.php?lan ... #debugging
mmontu wrote: Tue Oct 15, 2019 3:31 pm I ended up using TChromium.OnConsoleMessage and checking if Level=LOGSEVERITY_ERROR.
I 'got the Message, line and source. :)
I'm glad you could get the information you needed. :)