0

I'm using CEF 4. There are two instances of chromium on the form, they both use the same settings:

    procedure CreateGlobalCEFApp;
    var
      inicef: Tinifile;
    begin
      GlobalCEFApp := TCefApplication.Create;
      GlobalCEFApp.LogFile := 'debug.log';
      GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO;
      GlobalCEFApp.cache := 'cache';
      GlobalCEFApp.EnablePrintPreview := True;
      path := ExtractFilePath(ParamStr(0));
      GlobalCEFApp.DisableFeatures := 'WinUseBrowserSpellChecker';
      inicef := Tinifile.Create(path + '\settings.ini');
      GlobalCEFApp.UserAgent := Pchar(inicef.ReadString('Chrome', 'UserAgent', ''));
      inicef.free;
    end;

How can I make each instance use a different path for cookies? I need to log in with two accounts to the same site.

273K
  • 29,503
  • 10
  • 41
  • 64
Sten
  • 9
  • 1

2 Answers2

1

From a previous question it seems that CEF stores the cookie location in the cache path. You can set the GlobalCEFApp.cache property to a different location for each instance.

Adriaan
  • 806
  • 7
  • 24
  • Even more obvious because of the file named `Cookies` in there, which is an SQLite database. – AmigoJack Jun 22 '22 at 10:54
  • Yes, cookies are stored in the cache folder. I can't find an example how to set different settings for two instances. You said you can set a different GlobalCEFApp.cache for each instance, please give an example, I can't think of it – Sten Jun 22 '22 at 12:34
  • 2
    @Sten What? Just use different folder names, f.e. `GlobalCEFApp1.cache := 'cache1';` and `GlobalCEFApp2.cache := 'cache2';`. – AmigoJack Jun 22 '22 at 12:52
  • Using different folder names is understandable, I can’t figure out how to specify that chromium1 uses cache1, and chromium 2 uses cache2 As you wrote: "GlobalCEFApp1..." delphi swears, chromium does not have such a parameter, there is only GlobalCEFApp – Sten Jun 22 '22 at 15:12
  • @Sten Please edit your question to show more code and an explanation to how you are creating the chromium instances. Your code does not make sense with your explination of 2 instances. – Adriaan Jun 22 '22 at 17:06
  • @Sten Your `GlobalCEFApp` is just another variable. Wherever it is declared (not shown in your question's code example) you have to make 2 declarations out of it, so you have 2 variables. This is very basic understanding of programming - maybe you should first practice this with much simpler components (f.e. `TButton`) before riding the dragon with Chromium. – AmigoJack Jun 22 '22 at 20:12
  • There are two Chromium and CEFWindowParent components on the form. I create a browser on a timer `Timer_createcef1.Enabled := false; if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) and not(Chromium1.Initialized) then Timer_createcef1.Enabled := True;` (also for the second one) Before creating the form, the `CreateGlobalCEFApp` procedure written in the post is called – Sten Jun 23 '22 at 01:49
  • I use the version CEF4 – Sten Jun 23 '22 at 02:16
  • CEF4Delphi is not a version CEF4, it is CEF four Delphi - CEF for Delphi, "four" is pronounced like "for" is pronounced. – 273K Jun 23 '22 at 05:01
0

The cookies are inside the cache directory and you need to create browsers using different cache directories if you want them to be independent.

Create a new request context with a different cache directory and pass it when you call TChromium.CreateBrowser to create the second browser.

The MDIBrowser demo shows how to create new independent browsers here.

Read the code comments in that demo. CEF requires that all the cache directories must be a subdirectory of the GlobalCEFApp.RootCache directory.

CEF can't be initialized more than once per process. Create only one GlobalCEFApp instance and then create all the browsers that you need using MDI forms, tabs, frames, etc. There are CEF4Delphi demos showing how to do all of them.