Page 1 of 1
Re: about set cookies
Posted: Thu May 31, 2018 7:32 am
by salvadordf
Hi,
Cookies are usually stored in the
cache directory and you need to set a cache directory to save the cookies.
Most of the demos have the same cache for all the browsers they might create and you can set the cache directory by adding this code line before the GlobalCEFApp.StartMainProcess call in the DPR file.
Code: Select all
GlobalCEFApp.cache := 'c:\MyCacheDirectory';
For the MDIBrowser demo you can set an individual cache directory for each child form in the TChildForm.FormShow procedure, inside the uChildForm.pas file. Modify the context creation with this :
Code: Select all
TempContext := TCefRequestContextRef.New('c:\MyCacheDirectoryForThisChildForm', '', False, False, False, False)
Then run the demo and check the "
Create a new request context for new browsers" checkbox before creating child forms.
If you need to store the cookies in a different directory than the cache you will need to add this to the DPR file :
Code: Select all
GlobalCEFApp.cookies := 'c:\MyCookiesDirectory';
In the case of the MDIBrowser, you would also need to add the cookies directory to the browser creation in the TChildForm.FormShow procedure :
Code: Select all
Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext, 'c:\MyCookiesDirectoryForThisChildForm');
PS : Make sure your app has write privileges in the cache and cookies directories.
Re: about set cookies
Posted: Thu Jul 25, 2019 10:18 am
by X11
Hi!
Code: Select all
GlobalCEFApp.cookies := 'c:\MyCookiesDirectory';
[dcc32 Error] uMiniBrowser.pas(958): E2003 Undeclared identifier: 'cookies'
Delphi Tokyo
Re: about set cookies
Posted: Thu Jul 25, 2019 10:20 am
by salvadordf
Hi,
CEF removed the possibility to set a different directory for the cookies recently.
The cookies are saved inside the "cache" directory now.
Re: about set cookies
Posted: Thu Jul 25, 2019 10:30 am
by X11
Re: about set cookies
Posted: Thu Jul 25, 2019 10:33 am
by salvadordf
Check that the user running your application can create and modify files inside the cache directory.
Re: about set cookies
Posted: Thu Jul 25, 2019 12:10 pm
by X11
Yes.
I can create this directiry. And delete, and edit.
Re: about set cookies
Posted: Thu Jul 25, 2019 12:16 pm
by salvadordf
I'm sorry. I meant that the user account in your Windows system must have write privileges in that directory.
Try one of the demos (MiniBroser or SimpleBrowser2) and add this code line before the GlobalCEFApp.StartMainProcess call in the DPR file :
Re: about set cookies
Posted: Thu Jul 25, 2019 1:05 pm
by X11
I meant that the user account in your Windows system must have write privileges in that directory.
I understood you.
I execute the program under the user from the administrator's right and I have the right to write to this folder.
Dir is empty
http://prntscr.com/ojwodt
Code: Select all
procedure TMiniBrowserFrm.FormShow(Sender: TObject);
begin
ShowStatusText('Initializing browser. Please wait...');
// WebRTC's IP leaking can lowered/avoided by setting these preferences
// To test this go to https://www.browserleaks.com/webrtc
Chromium1.WebRTCIPHandlingPolicy := hpDisableNonProxiedUDP;
Chromium1.WebRTCMultipleRoutes := STATE_DISABLED;
Chromium1.WebRTCNonproxiedUDP := STATE_DISABLED;
// GlobalCEFApp.PersistSessionCookies := True;
GlobalCEFApp.Cache := 'cache';//ExtractFilePath(Application.ExeName) + 'Cache\' ;
GlobalCEFApp.UserDataPath := 'UserData';// ExtractFilePath(Application.ExeName) + 'UserData\';
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
// If it's not initialized yet, we use a simple timer to create the browser later.
if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) then Timer1.Enabled := True;
end;
Re: about set cookies
Posted: Thu Jul 25, 2019 1:12 pm
by X11
I understood.
It is necessary to set the parameters befor the line
Code: Select all
if GlobalCEFApp.StartMainProcess then
So.
That's right:
Code: Select all
GlobalCEFApp.cache := 'cache';
GlobalCEFApp.StartMainProcess;
And it is NOT right:
Code: Select all
GlobalCEFApp.StartMainProcess;
GlobalCEFApp.cache := 'cache';
Re: about set cookies
Posted: Thu Jul 25, 2019 1:26 pm
by salvadordf
That's correct.
Most of the GlobalCEFApp properties need to be set before the GlobalCEFApp.StartMainProcess call because they are used in the CEF initialization inside the GlobalCEFApp.StartMainProcess function.
Just one more thing. GlobalCEFApp.StartMainProcess must be in in a
if..then clause unless the application uses a different EXE for the subprocesses.
If your application uses the same EXE for all the CEF processes then the DPR file should have something similar to this :
Code: Select all
GlobalCEFApp := TCefApplication.Create;
// Set your GlobalCEFApp properties here.
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
{$IFDEF DELPHI11_UP}
Application.MainFormOnTaskbar := True;
{$ENDIF}
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
DestroyGlobalCEFApp;