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.

How delete domain cookies

Post Reply
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How delete domain cookies

Post by salvadordf »

There are 2 ways to do that :
  • Create a similar function to TChromium.DeleteCookies and call TempManager.DeleteCookies(URL, CookieName, nil) with a custom URL and CookieName. You can use just the URL and leave the CookieName blank.
  • Use the code in the CookieVisitor demo. Set deleteCookie to TRUE in the CookieVisitorProc procedure when domain has the right value.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How delete domain cookies

Post by salvadordf »

The CEF code comments for DeleteCookies are these :

Code: Select all

  ///
  // Delete all cookies that match the specified parameters. If both |url| and
  // |cookie_name| values are specified all host and domain cookies matching
  // both will be deleted. If only |url| is specified all host cookies (but not
  // domain cookies) irrespective of path will be deleted. If |url| is NULL all
  // cookies for all hosts and domains will be deleted. If |callback| is non-
  // NULL it will be executed asnychronously on the IO thread after the cookies
  // have been deleted. Returns false (0) if a non-NULL invalid URL is specified
  // or if cookies cannot be accessed. Cookies can alternately be deleted using
  // the Visit*Cookies() functions.
  ///
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How delete domain cookies

Post by salvadordf »

I added the url and cookieName parameters to TChromium.DeleteCookies a few days ago.
Download the latest version of CEF4Delphi and call TChromium.DeleteCookies(myUrl) or TChromium.DeleteCookies(myUrl, myCookieName) if you want to delete the cookies that match myUrl and myCookieName.

If you prefer the second way to delete cookies, just modify the CookieVisitorProc procedure in uCookieVisitor.pas from the CookieVisitor demo. Replace the line 149 with something like this :

Code: Select all

deleteCookie := domain = 'google.com';
That will delete all the cookies from the google.com domain.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How delete domain cookies

Post by salvadordf »

Both methods delete cookies in a different way. This is what the CEF code comments say about using the "DeleteCookies" function :

Code: Select all

If only |url| is specified all host cookies (but not domain cookies) irrespective of path will be deleted.
If you need absolute control about the conditions to delete any cookie modify CookieVisitorProc from the CookieVisitor demo and set deleteCookie to TRUE when you receive certain domain, path, name, etc.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How delete domain cookies

Post by salvadordf »

If you need to delete all cookies from google.com check that the domain parameter ends with '.google.com' and set deleteCookie to TRUE.

For more information about cookie domains read this :
https://stackoverflow.com/questions/106 ... mains-work
Post Reply