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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Cookies - how to save/load cookies?

Post Reply
voltov
Posts: 14
Joined: Tue Jun 13, 2017 11:01 am

Cookies - how to save/load cookies?

Post by voltov »

Hi!

Each time I reopen my app I have to re-login on a website. How do I save cookies?

Also is it possible to add/remove cookies programmatically?
voltov
Posts: 14
Joined: Tue Jun 13, 2017 11:01 am

Re: Cookies - how to save/load cookies?

Post by voltov »

GlobalCEFApp.PersistSessionCookies := True;

Found it =)
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cookies - how to save/load cookies?

Post by salvadordf »

Hi,

Most of the times you can fix that problem by setting the GlobalCEFApp.cache and GlobalCEFApp.cookies properties before the GlobalCEFApp.StartMainProcess call.

GlobalCEFApp.PersistSessionCookies has a different purpose.

This is what the CEF code comments say about that setting :

Code: Select all

  ///
  // To persist session cookies (cookies without an expiry date or validity
  // interval) by default when using the global cookie manager set this value to
  // true (1). Session cookies are generally intended to be transient and most
  // Web browsers do not persist them. A |cache_path| value must also be
  // specified to enable this feature. Also configurable using the
  // "persist-session-cookies" command-line switch. Can be overridden for
  // individual CefRequestContext instances via the
  // CefRequestContextSettings.persist_session_cookies value.
  ///
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cookies - how to save/load cookies?

Post by salvadordf »

linglung wrote: Thu Sep 07, 2017 6:17 am how to delete cookies or cache while program is running?
The easiest way is by calling TChromium.DeleteCookies.

You can also get an interface of the cookie manager and call CookieManager.DeleteCookies

And you can also use the CookieVisitor demo code and set deleteCookie to True in the CookieVisitorProc for every cookie you want to delete.

As far as I know, there's no way to clear the cache while the program is running.
More info here :
http://magpcss.org/ceforum/viewtopic.php?f=7&t=293

You can delete the contents of the cache directory before the GlobalCEFApp.StartMainProcess call or after the GlobalCEFApp.Free call.
Be careful and delete the directory in the main process only.
Post Reply