I'm trying to implement GlobalCEFApp.OnUncaughtException, but it doesn't seem to fire.
I have:
GlobalCEFApp.UncaughtExceptionStackSize := 20;
GlobalCEFApp.OnUncaughtException := CefRenderProcess_OnUncaughtException;
in the render process, and have a simple page with a button:
<input type="button" onclick="throw new Error('Boom');" value="Error">
But clicking the button doesn't report the error to CEF. Is the CEF implementation currently broken? And could you expand a demo to include this feature?
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.
GlobalCEFApp.OnUncaughtException not firing/no demo
- salvadordf
- Posts: 4374
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: GlobalCEFApp.OnUncaughtException not firing/no demo
Hi,
That event is executed in the render process and it's not possible to set a breakpoint to debug it.
I just added an example in the MiniBrowser demo. Read the code comments in GlobalCEFApp_OnUncaughtException :
https://github.com/salvadordf/CEF4Delphi/blob/69adbfb115570a7e26bdec7ea2e8592370af1c6e/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L283
Follow these steps :
That event is executed in the render process and it's not possible to set a breakpoint to debug it.
I just added an example in the MiniBrowser demo. Read the code comments in GlobalCEFApp_OnUncaughtException :
https://github.com/salvadordf/CEF4Delphi/blob/69adbfb115570a7e26bdec7ea2e8592370af1c6e/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L283
Follow these steps :
- Navigate to https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_throw_error
- Remove the try..catch code lines.
- Click in the "Run" button.
- Type 42 in the edit box.
- Click on the "Test input" button.
- You will see a "JS exception" text in the status bar.
Re: GlobalCEFApp.OnUncaughtException not firing/no demo
Now try it w/ the Browser Subprocess demo. Since it doesn't implement Dev Tools, just use:
Code: Select all
procedure GlobalCEFApp_OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace);
begin
OutputDebugString(PChar('GlobalCEFApp_OnUncaughtException'));
// This code runs in the render process and we can't set a breakpoint to debug it from the main application process.
// Read this for more information about debugging CEF subprocesses :
// https://www.briskbard.com/index.php?lang=en&pageid=cef#debugging
// In this example we only use the "console trick" explained in the DOMVisitor demo to send some custom text to the
// main process that will be received in TChromiumCore.OnConsoleMessage
// Load the following page and delete the try..catch lines to test this event :
// https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_throw_error
if assigned(frame) and frame.IsValid then
frame.ExecuteJavaScript('console.log("GlobalCEFApp_OnUncaughtException");', '', 0);
end;
Re: GlobalCEFApp.OnUncaughtException not firing/no demo
This is strange, I thought the GlobalCEFApp_OnUncaughtException would need to be implemented in the Subprocess, not within the main process. When I implement it in the main process, it does fire.
Re: GlobalCEFApp.OnUncaughtException not firing/no demo
After further review, the end result seems to be:
In the main process you need to assign
And in the sub process:
In the main process you need to assign
Code: Select all
GlobalCEFApp.UncaughtExceptionStackSize := 50;
Code: Select all
GlobalCEFApp.OnUncaughtException := GlobalCEFApp_OnUncaughtException;