Page 1 of 1

Re: delete cache

Posted: Thu Jan 10, 2019 8:12 am
by salvadordf
Set GlobalCEFApp.DeleteCache to TRUE before the GlobalCEFApp.StartMainProcess call in the DPR file and CEF4Delphi will delete the cache before CEF is initialized.

Re: delete cache

Posted: Thu Jan 10, 2019 8:26 am
by salvadordf
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

Re: delete cache

Posted: Thu Jan 10, 2019 9:10 am
by salvadordf
beryindo wrote: Thu Jan 10, 2019 8:43 amMDIBrowser can create and delete so can GlobalCEFApp.DeleteCache := True before Browser Create ?
You need to set GlobalCEFApp.DeleteCache before the GlobalCEFApp.StartMainProcess call in the DPR file.

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".
beryindo wrote: Thu Jan 10, 2019 8:43 ambut can MDIBrowser delete cookies and set user agent ?
Yes. That demo can delete cookies and you can modify the request headers to set a new user agent.

Re: delete cache

Posted: Thu Jan 10, 2019 10:12 am
by salvadordf
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.

Re: delete cache

Posted: Thu Jan 10, 2019 10:20 am
by salvadordf
Put a breakpoint in CookieVisitorProc and check that ChildForm exists and has a valid handle.

Also check that ChildForm receives the SHOWCOOKIES message.

Re: delete cache

Posted: Thu Jan 10, 2019 1:12 pm
by salvadordf
Build the CookieVisitor demo and check that it works in your computer. Then add your code to that demo incrementally.

Re: delete cache

Posted: Thu Jan 10, 2019 3:39 pm
by salvadordf
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 :

Code: Select all

TempManager := NewChildContext.GetDefaultCookieManager(nil);
Then you can call TempManager.VisitAllCookies(FVisitor) to get the cookies.

Re: delete cache

Posted: Fri Jan 11, 2019 10:10 am
by salvadordf
Right now I'm very busy. I'll try to take a look at this over the weekend.

Re: delete cache

Posted: Sun Jan 13, 2019 3:31 pm
by salvadordf
Sorry for the delay.

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;
Then modify TChildForm.Button2Click like this :

Code: Select all

procedure TChildForm.Button2Click(Sender: TObject);
var
  TempManager : ICefCookieManager;
begin
    TempManager := NewChildContext.GetDefaultCookieManager(nil);
    TempManager.VisitAllCookies(FVisitor);
end;
You will also have to set NewChildContext to NIL in the FormCloseQuery procedure

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;