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.

CEF4Delphi cookies

Post Reply
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

CEF4Delphi cookies

Post by amiran6543 »

Hello, please help with cookies, how to make different cookies for each element of chromium???
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF4Delphi cookies

Post by salvadordf »

Hi,

You need to create independent browsers.

The MDIBrowser demo has all the code you need for that. Build it and check the "Create a new request context for new browsers" checkbox to create independent browsers.

This is the function that creates each child browser with a new request context to make them independent :
https://github.com/salvadordf/CEF4Delphi/blob/668e4ab25fc6c305ec447d10c64e742d29f09984/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L218
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

Re: CEF4Delphi cookies

Post by amiran6543 »

Thank you, I saw this example, but I didn't understand how to do it exactly by clicking on the button, for example, I click on one of the many buttons and a website opens with saved cookies and cookies, and so different cookies for different buttons with the chromium component!
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF4Delphi cookies

Post by salvadordf »

When you check the "Create a new request context for new browsers" checkbox and you create a new browser it will have a unique request context with a different cache folder.

Each cache folder has a different database with the web browser cookies.

This means that the cookies on one browser will not be visible by the rest of the browsers because each browser uses a different cache.
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

Re: CEF4Delphi cookies

Post by amiran6543 »

I understand you, well, for example, I want to do this without opening another form, all in one form, by pressing a button
as I understand it, the code should look like this:

procedure TMainForm.Button1Click(Sender: TObject);
var
TempContext : ICefRequestContext;
TempCache : string;
begin

TempCache := GlobalCEFApp.RootCache + '\cache' + inttostr(MainForm.BrowserCount);

TempContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False) ;

Chromium1.DefaultURL := Edit1.Text;
Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext);
end;
But swears on a line : TempContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False) ;
Error E2034 Too many actual parameters
I would be grateful if you can help!!
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF4Delphi cookies

Post by salvadordf »

There were some changes in the API recently that modified the parameters in that function.

If you see that error it means that Delphi is still using some old compiled units.
Sometimes Delphi keeps outdated DCU and BPL files that could cause this issue.
Uninstall CEF4Delphi and install it again. Follow this guide :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=772#p3481
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

Re: CEF4Delphi cookies

Post by amiran6543 »

Thank you very much, it helped!
Post Reply