Page 1 of 1

cookie

Posted: Fri Sep 04, 2020 1:48 pm
by kotyara
Hello, i would like to know :
How to assign a separate folder for storing cookie and cache for each and every Chromium
I used to do it like that:

Code: Select all

String sCookies = "C://qwe/br_1/CookiesDir";
String sCache = "C://qwe/br_1/CacheDir";
_di_ICefRequestContext FRequestContext = TCefRequestContextRef::New(sCache, L"en-US,ru-RU", true, true, true, false);
Chromium->CreateBrowser(CEFWindowParent, "Browser"+IntToStr(i), FRequestContext, sCookies, true);
But everything has changed, can you help me?

Re: cookie

Posted: Fri Sep 04, 2020 2:26 pm
by salvadordf
Hi,

CEF removed the possibility to use a different directory for the cookies several months ago.
If you use the latest CEF libraries then you can only set the cache directory. The cookies will be stored in the same directory as the cache.

If you want to create a bunch of independent browsers in one application you can use a very similar code than the one you gave.

You would only have to create a request context with an independent "cache" parameter for each browser.
The MDIBrowser demo has all the code you need :
https://github.com/salvadordf/CEF4Delph ... m.pas#L217

This forum thread has more detials :
viewtopic.php?f=8&t=1122

Re: cookie

Posted: Sat Sep 05, 2020 4:04 pm
by kotyara
There was a problem like this:
Does the "Cookies" file contain only a name without a value? What could be the reason?
Снимок.PNG

Re: cookie

Posted: Sat Sep 05, 2020 4:14 pm
by salvadordf
That file is managed by Chromium internally.

I could be wrong but the real value might be hidden in the "encrypted_value" column.

Re: cookie

Posted: Sat Sep 05, 2020 4:25 pm
by kotyara
Yes, there is data in this column, I did not notice it.
But the next time I start the program, I am not authorized on the site again. =(

Re: cookie

Posted: Sun Sep 06, 2020 12:44 pm
by kotyara
Here's another thing I noticed:
If the program is given a cookie file from the old version, where the value is not encrypted, it will start authorized on the site and everything is OK, but after closing it, it will move the value to "encrypted_value" and at the next launch it will start not authorized.

Re: cookie

Posted: Sun Sep 06, 2020 1:02 pm
by salvadordf
Please, check that you set GlobalCEFApp.RootCache property before the GlobalCEFApp.StartMainProcess call in the DPR file.

GlobalCEFApp.RootCache must be a parent directory to all the cache directories used by the browsers in your application as explained here :
viewtopic.php?f=8&t=1122&start=10#p6242

This is very important to Chromium because it stores a file called "LocalPrefs.json" with the keys to decrypt the cookie values in that directory. Without it, the browser will not be able to decrypt the cookies and the session will be closed the next time you open that website.