Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Intercept JS errors ?
-
- Posts: 513
- Joined: Thu Aug 10, 2017 12:40 pm
Intercept JS errors ?
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.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Intercept JS errors ?
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.
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.
-
- Posts: 513
- Joined: Thu Aug 10, 2017 12:40 pm
Re: Intercept JS errors ?
In this case a JS error will throw a Delphi exception ?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.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Intercept JS errors ?
No. The JS error will only trigger the GlobalCEFApp.OnUncaughtException event in the render process.thefunkyjoint wrote: Wed Feb 13, 2019 11:21 amIn this case a JS error will throw a Delphi exception ?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.
The "OnUncaughtException" name is just the CEF method name for that event but it has nothing to do with Delphi exceptions.
-
- Posts: 513
- Joined: Thu Aug 10, 2017 12:40 pm
Re: Intercept JS errors ?
Thanks, is there any example on any demo ?
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Intercept JS errors ?
I'm afraid not.
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 :

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 :
- ICefV8Context -> https://magpcss.org/ceforum/apidocs3/pr ... ntext.html
- ICefV8Exception -> https://magpcss.org/ceforum/apidocs3/pr ... ption.html
- ICefV8StackTrace -> https://magpcss.org/ceforum/apidocs3/pr ... Trace.html
- ICefV8StackFrame -> https://magpcss.org/ceforum/apidocs3/pr ... Frame.html
Code: Select all
browser.SendProcessMessage(PID_BROWSER, msg);
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Intercept JS errors ?
I just edited my previous post. In case you read the old version, reload this page.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Intercept JS errors ?
GlobalCEFApp.OnUncaughtException is executed in the render process. You need to use the debugging techniques described here :mmontu wrote: Tue Oct 15, 2019 2:51 pm I have tried UncaughtExceptionStackSize with:
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?Code: Select all
GlobalCEFApp.UncaughtExceptionStackSize := 10; GlobalCEFApp.OnUncaughtException := MyAppOnUncaughtException;
https://www.briskbard.com/index.php?lan ... #debugging
I'm glad you could get the information you needed.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.![]()
