How do I clear the cache and cookies for an embedded Chromium browser?

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I created a browser with TChromium. The TChromium is created dynamically. Facebook access (login) At the end of the process, the component is destroyed. The problem occurs when the component is created again He continues with the previous session (login). I need to clean all cache and cookies. (Force Log out)

Below the code I create the component by:

I destroy it and release memory like this:

FreeAndNil(Chromium) 

What should I do?

回答1:

DCEF1:

To delete cookies in DCEF1 wrapper there's the DeleteCookies function in ICefCookieManager manager interface. However, I've tried the following code to delete all cookies, but it always failed to me:

procedure TForm1.Button1Click(Sender: TObject); var   CookieManager: ICefCookieManager; begin   CookieManager := TCefCookieManagerRef.GetGlobalManager;   if not CookieManager.DeleteCookies('', '') then     ShowMessage('DeleteCookies failed!'); end; 

Fortunately, there is another option to delete cookies using this cookie manager. Visit all of them and in the visitor function assign True to the deleteCookie output parameter. Be careful with getting cookie manager, it's created the first time you navigate somewhere (the GetGlobalManager class function is unsafe, it's not properly handled for unexpected result), so be sure you'll use this code after navigation:

procedure TForm1.Button1Click(Sender: TObject); var   CookieManager: ICefCookieManager; begin   CookieManager := TCefCookieManagerRef.GetGlobalManager;   CookieManager.VisitAllCookiesProc(     function(const name, value, domain, path: ustring; secure, httponly,       hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;       count, total: Integer; out deleteCookie: Boolean): Boolean     begin       deleteCookie := True;       ShowMessage('A cookie from domain ' + domain + ' will be unmercifully ' +         'deleted!');     end   ); end; 

DCEF3:

In DCEF3 wrapper you can use the following. Credit goes to Eric Santos:

type   CefTask = class(TCefTaskOwn)     procedure Execute; override;   end;  procedure CefTask.Execute; var   CookieManager: ICefCookieManager; begin   CookieManager := TCefCookieManagerRef.Global;   CookieManager.DeleteCookies('', ''); end;  procedure ClearCookies; var   Task: CefTask; begin   Task := CefTask.Create;   CefPostTask(TID_IO, Task); end; 


回答2:

TLama your help was decisive for my project. I am grateful for sharing your experience.

Solved my problem with this code:

procedure TForm1.Button1Click(Sender: TObject); var   CookieManager: ICefCookieManager; begin   CookieManager := TCefCookieManagerRef.GetGlobalManager;   CookieManager.VisitAllCookiesProc(     function(const name, value, domain, path: ustring; secure, httponly,       hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;       count, total: Integer; out deleteCookie: Boolean): Boolean     begin       deleteCookie := True;       ShowMessage('A cookie from domain ' + domain + ' will be unmercifully ' +         'deleted!');     end   ); end; 

hug



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!