Cef4 cookies

Post Reply
Kazann116
Posts: 6
Joined: Sat Dec 08, 2018 7:34 am

Cef4 cookies

Post by Kazann116 » Mon Apr 15, 2019 4:27 pm

Hello everyone, in cef3 there is a code for quickly creating cookies, and why it is impossible to do this in cef4? mb there is a version of this for quick switching cookies in the browser for example, I want to quickly switch between facebook accounts, how do i implement this?
here in cef3 there is this code

CookieManager: ICefCookieManager;
CookiesPath : String;
begin
CookiesPath := ExtractFilePath(Application.ExeName) + ' Cookies/User1';
CookieManager := TCefCookieManagerRef.Global;
CookieManager.SetStoragePath(CookiesPath, TRUE );
Chromium1.Load('http://vk.com/');

User avatar
salvadordf
Posts: 1653
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cef4 cookies

Post by salvadordf » Mon Apr 15, 2019 9:48 pm

Hi,

The CookieVisitor demo shows how to visit, create and delete cookies.

CEF4Delphi uses the SetStoragePath function too to set the new path to store the cookies :
https://github.com/salvadordf/CEF4Delphi/blob/dbc4900358d3ac344f38e298c145f44ebb635abb/source/uCEFChromium.pas#L1213

I've never tried to change the cookie's path of an existing browser. I don't know if the current CEF binaries support that feature but you can always create a new child browser with a different context and a different path for the cookies.

The MDIBrowser demo has the code to create child browsers with different contexts. All you need is to set a different path for the cache and cookies here :
https://github.com/salvadordf/CEF4Delphi/blob/dbc4900358d3ac344f38e298c145f44ebb635abb/demos/MDIBrowser/uChildForm.pas#L211

The cache path is the 1st parameter in TCefRequestContextRef.New, and the cookies path is the 4th parameter in Chromium1.CreateBrowser.

Post Reply