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.

Commandline parameters to a SubProcessBrowser

Post Reply
Briskitte Bardot
Posts: 6
Joined: Mon Sep 14, 2020 6:04 am

Commandline parameters to a SubProcessBrowser

Post by Briskitte Bardot »

Hello,

Thanks to all your great, and well commented demo applications I have learned a lot about how to use CEF4Delphi.
One thing I haven't found is if I can send commandline parameters to a SubProcessBrowser?

For example I have
GlobalCEFApp.BrowserSubprocessPath := 'MySubProcessBrowser.exe';

To ensure that main process and subprocess are using the same folders I'm looking for something like
GlobalCEFApp.BrowserSubprocessParameters := '/FWDir=C:\MyApp\CEF"/CacheDir=C:\Users\SomeUsername\AppData\Local\Temp\MyAppCEF1"';

Or maybe the commandline would contain a path to an ini-file containing additional settings.
User avatar
salvadordf
Posts: 4084
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Commandline parameters to a SubProcessBrowser

Post by salvadordf »

Try using the "aExtraInfo" parameter in the TChromiumCore.CreateBrowser function.

aExtraInfo will be passed as "extra_info" in the TCefApplicationCore.OnBrowserCreated event which is executed in the render process.

These are the code comments for the TCefApplicationCore.OnBrowserCreated event :
///
// Called after a browser has been created. When browsing cross-origin a new
// browser will be created before the old browser with the same identifier is
// destroyed. |extra_info| is an optional read-only value originating from
// cef_browser_host_t::cef_browser_host_create_browser(),
// cef_browser_host_t::cef_browser_host_create_browser_sync(),
// cef_life_span_handler_t::on_before_popup() or
// cef_browser_view_t::cef_browser_view_create().
///
See the TChromiumCore.SetUserAgentOverride function to know how to use a ICefDictionaryValue variable.
Briskitte Bardot
Posts: 6
Joined: Mon Sep 14, 2020 6:04 am

Re: Commandline parameters to a SubProcessBrowser

Post by Briskitte Bardot »

It sounded good, but I can't get your suggestion to work.
When the main process starts the subprocess I get "Error loading libcef.dll". I assume that it is too late to set GlobalCEFApp.FrameworkDirPath (and other paths) in the OnBrowserCreated event?

Maybe I misunderstood something. I can add that I'm using "Delphi 7" for this project. This is what I did:

In my main application I have the following code

Code: Select all

  try
    BrowserParams := TCefDictionaryValueRef.New;
    BrowserParams.SetString('/FWDir', GlobalCEFApp.FrameworkDirPath);
    BrowserParams.SetString('/CacheDir', GlobalCEFApp.Cache);

    if not Chromium1.CreateBrowser(WebBrowser1, '', nil, BrowserParams) then
      Timer1.Enabled := True;
  finally
    BrowserParams := nil;
  end;
In my sub process application I have the following code

Code: Select all

type
  //In Delphi 7 the event needs to be part of an object
  TSubCEFApp = class(TObject)
  public
    procedure OnBrowserCreated(const browser: ICefBrowser; const extra_info: ICefDictionaryValue);
  end;

var
  SubCEFApp : TSubCEFApp;
  
procedure TSubCEFApp.OnBrowserCreated(const browser: ICefBrowser; const extra_info: ICefDictionaryValue);
begin
  GlobalCEFApp.FrameworkDirPath := extra_info.GetString('/FWDir');
  GlobalCEFApp.ResourcesDirPath := GlobalCEFApp.FrameworkDirPath;
  GlobalCEFApp.LocalesDirPath := GlobalCEFApp.FrameworkDirPath + '\Locales';
  GlobalCEFApp.Cache := extra_info.GetString('/CacheDir');
  GlobalCEFApp.UserDataPath := GlobalCEFApp.Cache + '\UserData';
end;

begin
  GlobalCEFApp := TCefApplicationCore.Create;
  GlobalCEFApp.OnBrowserCreated := SubCEFApp.OnBrowserCreated;

  GlobalCEFApp.StartSubProcess;
  GlobalCEFApp.Free;
  GlobalCEFApp := nil;
end.
If I hardcode correct paths after "GlobalCEFApp := TCefApplicationCore.Create;" and alter my OnBrowserCreated event to
ShowMessage(extra_info.GetString('/FWDir') + #13#10 + extra_info.GetString('/CacheDir'));
Then the paths from the main process are displayed in the messagebox.
Briskitte Bardot
Posts: 6
Joined: Mon Sep 14, 2020 6:04 am

Re: Commandline parameters to a SubProcessBrowser

Post by Briskitte Bardot »

I just realised that what I need at the moment already exists on the commandline when the subprocess is executed.
--resources-dir-path
--locales-dir-path
--user-data-dir

Sorry for taking up your time.
Post Reply