delphidelphi-7chromium-embeddedcef4delphi

CEF4Delphi application can't run two instances


I have a Delphi application with an embedded CEF browser and it has stopped working since I updated if from CEF 117.1.4 and Chromium 117.0.5938.92 to CEF 123.0.12 and Chromium 123.0.6312.107.

With CEF 117 I can run two instances of the application with no issue, but now it fails on the second instance startup:

begin
  GlobalCEFApp := TCefApplication.Create;

  InicializaCef;

  // Reducir el número de locales a un mínimo
  GlobalCEFApp.LocalesRequired := 'ca,de,en-GB,en-US,es-419,es,fr,it,pt-BR,pt-PT';
  GlobalCEFApp.SetCurrentDir := True;
  GlobalCEFApp.LocalesDirPath := 'locales';

  Application.Initialize;
  Application.Title := 'QBrowser';
  Application.CreateForm(TMainForm, MainForm);
  test := GlobalCEFApp.StartMainProcess;
  if test then
    Application.Run;

  GlobalCEFApp.Free;
  GlobalCEFApp := nil;
end.

GlobalCEFApp.StartMainProcess is now returning False.

Is there some new configuration value I'm overlooking?


Solution

  • CEF changed the way it initializes and now it checks if another app is running with the same RootCache setting. This feature was added in CEF 120.1.8.

    If GlobalCEFApp.Cache and GlobalCEFApp.RootCache are empty then the default platform specific directory will be used. In the case of Windows: %AppData%\Local\CEF\User Data\.

    Use of the default directory is not recommended in production applications. Multiple application instances writing to the same GlobalCEFApp.RootCache directory could result in data corruption.

    There are two ways to avoid this:

    1. Implement GlobalCEFApp.OnAlreadyRunningAppRelaunch to be notified when a new app instance is starting and open a new tab or child form with a web browser.
    2. Use a different GlobalCEFApp.RootCache directory for each app instance.

    Read the documentation for all the details (search for TCefApplicationCore as type) about: