Page 1 of 1

GlobalCEFApp.OnUncaughtException not firing/no demo

Posted: Fri Sep 22, 2023 9:04 pm
by jchoover
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?

Re: GlobalCEFApp.OnUncaughtException not firing/no demo

Posted: Sun Sep 24, 2023 2:29 pm
by salvadordf
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 :
  • 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

Posted: Mon Sep 25, 2023 6:55 pm
by jchoover
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

Posted: Mon Sep 25, 2023 7:18 pm
by jchoover
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

Posted: Mon Sep 25, 2023 7:33 pm
by jchoover
After further review, the end result seems to be:

In the main process you need to assign

Code: Select all

GlobalCEFApp.UncaughtExceptionStackSize := 50;
And in the sub process:

Code: Select all

GlobalCEFApp.OnUncaughtException := GlobalCEFApp_OnUncaughtException;