Clear Cookies in TChromium
Asked Answered
A

1

1

How to clear cookies in CEF3.1547 I have tried the following solution however this simply does nothing. Cookies are still present. Is there a better solution than this?

procedure TForm1.Button1Click(Sender: TObject);
var
  CookieManager: ICefCookieManager;
begin
  // login to site
  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
  );
  // visit the site again to see if cookies cleared..
end;
Angelita answered 28/8, 2013 at 16:50 Comment(5)
Yes. There is. Does the cookie manager in WACEF support DeleteCookies method ? The code from your question I wrote for DCEF 1 (date of that post was before DCEF 3 project was released). In DCEF 1 DeleteCookies didn't work for me. Maybe in that WACEF will.Observant
Welcome to Stack Overflow. There's a better way to ask this question. Instead of asking whether there is a better solution, just ask how to delete cookies. Then, post your code as an answer. You don't need to ask whether there's a better solution. If there is, someone else will post it as another answer, and people can vote on which one is better.Verity
@Observant delete_cookies is present in WACEF.Angelita
Then try to use it. You're looking for a better solution. Not me. I wrote that DeleteCookies method failed me constantly, but it was with DCEF 1. Maybe the new DeleteCookies method will work with a wrapper you're using.Observant
@Observant I have tested DeleteCookies, it doesn't work in CEF3 / WACEF.. Can you post how to run it on the IOThread?Angelita
S
0

Use this code to delete Cookies from Chromium Version CEF3:

Use c_WB_ClearCookies for deleating all Cookies

Use c_WB_Clear_url_Cookies for deleating all Cookies only from one speceally Url like this -> c_WB_Clear_url_Cookies('http://google.com','cookie_name');

type
  CefTask = class(TCefTaskOwn)
    procedure Execute; override;

    public
    var url,cookieName: ustring;
    constructor create; virtual;
  end;

constructor CefTask.create;
begin
  inherited create;
  url := '';
  cookieName := '';
end;

procedure CefTask.Execute;
var CookieManager: ICefCookieManager;
begin
  CookieManager := TCefCookieManagerRef.Global;
  CookieManager.DeleteCookies(url,cookieName);
end;

procedure c_WB_ClearCookies;
var Task: CefTask;
begin
  Task := CefTask.Create;
  CefPostTask(TID_IO, Task);
end;

// c_WB_Clear_url_Cookies('http://google.com','cookie_name');
procedure c_WB_Clear_url_Cookies(c_url,c_cookieName: ustring);
var Task: CefTask;
begin
  Task := CefTask.Create;
  Task.url := c_url;
  Task.cookieName := c_cookieName;
  CefPostTask(TID_IO, Task);
end;

For list all Cookies to get the cookieName use Procedure list_all_cookies

procedure pausek;
var M: TMsg;
begin
  while PeekMessage(M, 0, 0, 0, pm_Remove) do
    begin
      TranslateMessage(M);
      DispatchMessage(M);
    end;
end;

procedure pause(i:longint);
var j : nativeint;
begin
  for j := 1 to i do
    begin
      pausek;
      sleep(100);
    end;
end;



procedure list_all_cookies;
var CookieManager: ICefCookieManager;
    cookie_list : string;
const lf = chr(13) + chr(10); 
begin

  cookie_list := '';

  CookieManager := TCefCookieManagerRef.Global;

  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

      cookie_list := cookie_list + inttostr(count) + ': ' +  domain + ' - ' + name + ' - ' + value + ' - ' + path + lf;

     if (count<total) then result := true;

    end

  );

  pause(10);

  ShowMessage(cookie_list);
end;
Sesquialtera answered 11/3, 2016 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.