Page 1 of 1
Changing the cache
Posted: Fri Aug 19, 2022 8:55 am
by amiran6543
Hello, tell me how you can apply different cookies to one component of Tchrome, for example, I have 2 buttons, clicking opens a page with 1 cache and clicking on another page with another cache.
For example
if not(Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext)) then Timer1.Enabled := True;
procedure TForm1.Timer1Timer(Sender: TObject);
var
TempContext : ICefRequestContext;
TempCache:string;
begin
Timer1.Enabled := False;
TempCache := GlobalCEFApp.RootCache + '\root_cache\user1';
TempContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False) ;
form2.Chromium1.LoadURL('https://ya.ru/');
if not(Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext)) and not(Chromium1.Initialized) then
Timer1.Enabled := True
end;
All the same, only 1 path is applied, it does not react to the rest!
Re: Changing the cache
Posted: Fri Aug 19, 2022 9:49 am
by salvadordf
Hi,
The directory structure must be like this :
- GlobalCEFApp.RootCache must be a writable directory that will be the parent for all the cache directories.
- Each independent browser will use a different subdirectory of GlobalCEFApp.RootCache.
The result could be something like this :
- Root cache directory : c:\MyApp\RootCache
- Cache directory for the first independent browser : c:\MyApp\RootCache\cache1
- Cache directory for the second independent browser : c:\MyApp\RootCache\cache2
Perhaps the issue that you have is caused by the timer logic. I would suggest that you use the same solution as the MDIBrowser demo.
Use the GlobalCEFApp.OnContextInitialized event and the TForm.OnShow event to enable the interface when GlobalCEFApp.GlobalContextInitialized is true.
After that, you can call TChromium.CreateBrowser without timers.
Re: Changing the cache
Posted: Fri Aug 19, 2022 10:28 am
by amiran6543
Thanks to salvadordf, but even in this case it doesn't work, you have to close and reopen the program then it works, how can you implement it without restarting the program?
Code: Select all
procedure TForm1.Image1Click(Sender: TObject);
var
i: Integer;
TempContext : ICefRequestContext;
TempCache:string;
begin
TempCache := GlobalCEFApp.RootCache + '\root_cache\user1';
TempContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False) ;
Chromium1.LoadURL('https://ya.ru/');
Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext);
end;
procedure TForm1.Image2Click(Sender: TObject);
var
i: Integer;
TempContext : ICefRequestContext;
TempCache:string;
begin
TempCache := GlobalCEFApp.RootCache + '\root_cache\user2';
TempContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False) ;
Chromium1.LoadURL('https://ya.ru/');
Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext);
end;
Re: Changing the cache
Posted: Fri Aug 19, 2022 4:29 pm
by amiran6543
I still haven't found an answer, how to change the cache right while the program is running?

Re: Changing the cache
Posted: Sun Aug 21, 2022 8:56 am
by salvadordf
CEF only allows us to set the cache directory when we call TChromium.CreateBrowser.
That means that each browser has the same cache directory during its lifetime. If we need to use a browser with a different cache directory we have to create a new browser.
If your application needs to switch between several independent browsers you can create a new browser and then hide or destroy the previous browser.
You can use a TPageControl with hidden tabs to do all that. See the TabbedBrowser2 demo.