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?
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:
GlobalCEFApp.OnAlreadyRunningAppRelaunch
to be notified when a new app instance is starting and open a new tab or child form with a web browser.GlobalCEFApp.RootCache
directory for each app instance.Read the documentation for all the details (search for TCefApplicationCore
as type) about:
GlobalCEFApp.OnAlreadyRunningAppRelaunch
:
Implement this function to provide app-specific behavior when an already running app is relaunched with the same
TCefSettings.root_cache_path
value. For example, activate an existing app window or create a new app window.command_line
will be read-only. Do not keep a reference tocommand_line
outside of this function. Returntrue
(1
) if the relaunch is handled orfalse
(0
) for default relaunch behavior. Default behavior will create a new default styled Chrome window.To avoid cache corruption only a single app instance is allowed to run for a given
TCefSettings.root_cache_path
value. On relaunch the app checks a process singleton lock and then forwards the new launch arguments to the already running app process before exiting early. Client apps should therefore check thecef_initialize()
return value for early exit before proceeding.This function will be called on the browser process UI thread.
GlobalCEFApp.RootCache
:
The root directory for installation-specific data and the parent directory for profile-specific data. All
TCefSettings.cache_path
andICefRequestContextSettings.cache_path
values must have this parent directory in common. If this value is empty andTCefSettings.cache_path
is non-empty then it will default to theTCefSettings.cache_path
value. Any non-empty value must be an absolute path. If both values are empty then the default platform-specific directory will be used (~/.config/cef_user_data
directory on Linux,~/Library/Application Support/CEF/User Data
directory on MacOS,AppData\Local\CEF\User Data
directory under the user profile directory on Windows). Use of the default directory is not recommended in production applications (see below).Multiple application instances writing to the same
root_cache_path
directory could result in data corruption. A process singleton lock based on theroot_cache_path
value is therefore used to protect against this. This singleton behavior applies to all CEF-based applications using version 120 or newer. You should customizeroot_cache_path
for your application and implementICefBrowserProcessHandler.OnAlreadyRunningAppRelaunch
, which will then be called on any app relaunch with the sameroot_cache_path
value.Failure to set the
root_cache_path
value correctly may result in startup crashes or other unexpected behaviors (for example, the sandbox blocking read/write access to certain files).
GlobalCEFApp.Cache
:
The directory where data for the global browser cache will be stored on disk. If this value is non-empty then it must be an absolute path that is either equal to or a child directory of
TCefSettings.root_cache_path
. If this value is empty then browsers will be created in "incognito mode" where in-memory caches are used for storage and no profile-specific data is persisted to disk (installation-specific data will still be persisted in root_cache_path). HTML5 databases such aslocalStorage
will only persist across sessions if a cache path is specified. Can be overridden for individualICefRequestContext
instances via theICefRequestContextSettings.cache_path
value. When using the Chrome runtime any child directory value will be ignored and the "default" profile (also a child directory) will be used instead.