Page 1 of 1

Delete cookies

Posted: Mon Sep 02, 2019 1:36 pm
by thefunkyjoint
Hi,

I'm looking for a way to delete cookies WITHOUT having to exit my application.

To do so, i'm destroying the TChromium component and trying to delete the cookies dir. But still i receive an error telling my application is using the cookies dir. Any hints ?

Thanks !

Re: Delete cookies

Posted: Mon Sep 02, 2019 1:48 pm
by thefunkyjoint
Actually i've noticed when i run the code below :

chromium1.free;

Nothing happens, Chromium is still working.

Is there any right way to destroy the component ?

Re: Delete cookies

Posted: Mon Sep 02, 2019 1:56 pm
by salvadordf
Hi,

You can delete the cookies at runtime by calling TChromium.DeleteCookies.
The TChromium.OnCookiesDeleted event will notify you when they are deleted and how many were deleted.

If you need to select what cookies must be deleted while preserving other cookies then you will have to use a TCefFastCookieVisitor as shown in the CookieVisitor demo.

Read this for more information about the CookieVisitor :
https://magpcss.org/ceforum/apidocs3/pr ... sitor.html

CEF4Delphi uses a procedure that is executed when the "Visit" method is called. That procedure is called "CookieVisitorProc" In the CookieVisitor demo and it's specified when you create the TCefFastCookieVisitor instance.

Re: Delete cookies

Posted: Mon Sep 02, 2019 2:04 pm
by thefunkyjoint
I tried use the .deletecookies method, but somehow my browser instance is still logged on the website i'm browsing, so i assume the cookies are not entirely deleted.

I can achieve the result i desire by closing my app and manually delete the entire cookies dir, and reopening the app.

But i'm trying a way to do this without close / open my app.

Re: Delete cookies

Posted: Mon Sep 02, 2019 2:13 pm
by thefunkyjoint
If i want to do exactly this (delete entire cookies dir), what should be the procedure ?

This is what i'm trying :

1 - Destroy/free TChromium
2 - Delete the cookies dir
3 - Create TChromium

Problem is, in the step 2 Windows says my app is currently using the cookies dir.

Re: Delete cookies

Posted: Mon Sep 02, 2019 2:32 pm
by salvadordf
You can't delete the cache/cookies files manually while the application is running because CEF is using them.

If the session is still open after deleting the cookies it could mean that the website is using an alternative method to keep the session open without cookies. Search "maintain sessions without cookies" in Google for more information about this.

You can use CookieVisitor to see if there's any cookie left after the TChromium.DeleteCookies procedure is executed.
  • Run CookieVisitor and load your web page.
  • Login in that web page.
  • Right-click and select "Visit cookies" to see what cookies are available.
  • A new window shows some cookie information if there are any cookie available.
  • Right-click and select "Delete cookies".
  • A message dialog informs that the cookies were deleted.
  • Right-click and select "Visit cookies" to see what cookies are still available. If you don't see a new window with cookie information then it means that there are no cookies stored.

Re: Delete cookies

Posted: Tue Sep 03, 2019 1:04 am
by thefunkyjoint
Thank you for the detailed information Salvador ! :D