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.
delete cache
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
Set GlobalCEFApp.DeleteCache to TRUE before the GlobalCEFApp.StartMainProcess call in the DPR file and CEF4Delphi will delete the cache before CEF is initialized.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
I'm sorry but CEF3 doesn't allow to delete the cache while the browser is fully initialized. That's why I added the "GlobalCEFApp.DeleteCache" property.
Read this thread for more information :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=594
Read this thread for more information :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=594
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
You need to set GlobalCEFApp.DeleteCache before the GlobalCEFApp.StartMainProcess call in the DPR file.beryindo wrote: Thu Jan 10, 2019 8:43 amMDIBrowser can create and delete so can GlobalCEFApp.DeleteCache := True before Browser Create ?
MDIBrowser can be configured to create browsers with different "contexts", which means that they can use different cache directories. This is just a workaround to avoid closing your app each time you need to clear the cache with "GlobalCEFApp.DeleteCache".
Yes. That demo can delete cookies and you can modify the request headers to set a new user agent.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
You also need to call TempManager.VisitAllCookies(FVisitor) after you assign TempManager := TCefCookieManagerRef.Global(nil);
The CookieVisitor demo do that in the TCookieVisitorFrm.Chromium1ContextMenuCommand procedure but you can call VisitAllCookies in any browser thread or procedure.
The CookieVisitor demo do that in the TCookieVisitorFrm.Chromium1ContextMenuCommand procedure but you can call VisitAllCookies in any browser thread or procedure.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
Put a breakpoint in CookieVisitorProc and check that ChildForm exists and has a valid handle.
Also check that ChildForm receives the SHOWCOOKIES message.
Also check that ChildForm receives the SHOWCOOKIES message.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
Build the CookieVisitor demo and check that it works in your computer. Then add your code to that demo incrementally.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
If you create different request contexts for each child browser in the MDIBrowser demo then each child browser will also have a different cookie manager.
You will need to use those cookie managers to call "VisitAllCookies" and not the global cookie manager that's used in the CookieVisitor demo.
Let's say you create a custom request context for a new child browser in the MDIBrowser demo and you call it "NewChildContext". To get the cookie manager for that browser you only have to call :
Then you can call TempManager.VisitAllCookies(FVisitor) to get the cookies.
You will need to use those cookie managers to call "VisitAllCookies" and not the global cookie manager that's used in the CookieVisitor demo.
Let's say you create a custom request context for a new child browser in the MDIBrowser demo and you call it "NewChildContext". To get the cookie manager for that browser you only have to call :
Code: Select all
TempManager := NewChildContext.GetDefaultCookieManager(nil);
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
Right now I'm very busy. I'll try to take a look at this over the weekend.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: delete cache
Sorry for the delay.
You need to declare "NewChildContext : ICefRequestContext;" in the class, not in a procedure.
Assign NewChildContext in TChildForm.FormShow like this :
Then modify TChildForm.Button2Click like this :
You will also have to set NewChildContext to NIL in the FormCloseQuery procedure
You need to declare "NewChildContext : ICefRequestContext;" in the class, not in a procedure.
Assign NewChildContext in TChildForm.FormShow like this :
Code: Select all
procedure TChildForm.FormShow(Sender: TObject);
begin
NewChildContext := TCefRequestContextRef.New('', '', False, False, False, False);
Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext);
end;
Code: Select all
procedure TChildForm.Button2Click(Sender: TObject);
var
TempManager : ICefCookieManager;
begin
TempManager := NewChildContext.GetDefaultCookieManager(nil);
TempManager.VisitAllCookies(FVisitor);
end;
Code: Select all
procedure TChildForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := FCanClose;
NewChildContext := nil;
if not(FClosing) and Panel1.Enabled then
begin
FClosing := True;
Panel1.Enabled := False;
Chromium1.CloseBrowser(True);
end;
end;