1

如何在CEF3.1547中清除 cookie我尝试了以下解决方案,但这根本没有任何作用。Cookie 仍然存在。还有比这更好的解决方案吗?

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;
4

1 回答 1

0

使用此代码从 Chromium 版本 CEF3 中删除 Cookie:

使用 c_WB_ClearCookies 删除所有 Cookie

使用 c_WB_Clear_url_Cookies 仅从一个特殊的 Url 中删除所有 Cookies -> 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;

要列出所有 Cookie 以获取 cookieName,请使用过程 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;
于 2016-03-11T14:16:38.157 回答