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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

GlobalCEFApp.OnUncaughtException not firing/no demo

Post Reply
jchoover
Posts: 14
Joined: Tue Apr 30, 2019 5:45 pm

GlobalCEFApp.OnUncaughtException not firing/no demo

Post 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?
User avatar
salvadordf
Posts: 4374
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.OnUncaughtException not firing/no demo

Post 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.
jchoover
Posts: 14
Joined: Tue Apr 30, 2019 5:45 pm

Re: GlobalCEFApp.OnUncaughtException not firing/no demo

Post 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;
jchoover
Posts: 14
Joined: Tue Apr 30, 2019 5:45 pm

Re: GlobalCEFApp.OnUncaughtException not firing/no demo

Post 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.
jchoover
Posts: 14
Joined: Tue Apr 30, 2019 5:45 pm

Re: GlobalCEFApp.OnUncaughtException not firing/no demo

Post 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;
Post Reply