Page 1 of 1

GlobalCEFApp.DeleteCache will delete cookies too

Posted: Thu Jul 21, 2022 6:49 am
by tad.chen
I find that calling GlobalCEFApp.DeleteCache in the initialization of browser will delete cookies too. I uses ceflib 9X, Why?

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Thu Jul 21, 2022 8:22 am
by salvadordf
Thanks for reporting this issue!

It seems that Chromium moved the cookies to the "cache\Network" directory. I'll fix it as soon as I can.

If you need to delete the cache now try calling :

Code: Select all

TChromiumCore.ClearDataForOrigin('*', TCefClearDataStorageTypes.cdstCacheStorage);

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Thu Jul 21, 2022 1:21 pm
by salvadordf
The latest CEF4Delphi version at GitHub includes the fix for this issue.

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Sat Jul 23, 2022 4:14 am
by tad.chen
Sorry, maybe I've not described this problem clearly.

Because I use ceflib 95.X.X.X, in which cookies files such as cookies, Cookies-journal and LocalPrefs.json are located in cache directory, not in cache\network directory like ceflib 103.X.X.X.

I find that calling GlobalCEFApp.DeleteCache in the initialization of browser will cause logout from some websites. After that I check cookies in cookies file by sqlite browser, and find many cookies of that website disppear.

But these disppeared cookies are still there after calling GlobalCEFApp.DeleteCache. They disppear after I visit that website again!

If I've not called GlobalCEFApp.DeleteCache, I can log in that website when I visit it, and all the cookies of that website will not disppear.

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Sun Jul 24, 2022 9:22 am
by salvadordf
TCefApplicationCore.MoveCookiesDB needs to move the LocalPrefs.json file too and the latest CEF4Delphi update fixes that bug too.

In any case, I would suggest that you use TChromiumCore.ClearDataForOrigin and wait for the TChromiumCore.OnDevToolsMethodResult event because TChromiumCore.ClearDataForOrigin executes an asynchronous devtools method.

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Mon Jul 25, 2022 8:49 am
by tad.chen
Thank you for your advice.

But I'm not sure that TChromiumCore.ClearDataForOrigin has the same function of GlobalCEFApp.DeleteCache, because it seams that the size of cache directory hasn't changed after calling ClearDataForOrigin.

And in MiniBrowser DEMO, I click "Clear all storage for current URL" menuitem to invoke ClearDataForOrigin to clear all data including cookies of the website, But I can still log it the website next time. So, cookies of the website are not deleted.

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Mon Jul 25, 2022 9:00 am
by salvadordf
ClearDataForOrigin clears the data for one URL but if you use an asterisk as parameter it should delete all the local storage from all the URLs unless there's a bug in DevTools or in my code.

Edit : I just checked again and it seems to work correctly when you use an asterisk.

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Tue Jul 26, 2022 1:16 am
by tad.chen
Yes, using an asterisk as parameter like Chromium1.ClearDataForOrigin('*',cdstCookies) can delete cookies sucessfully. But using without an asterisk like Chromium1.ClearDataForOrigin(URLCbx.Text,cdstCookies) in Minibrowser can't delete cookies.

But I'm still not sure that TChromiumCore.ClearDataForOrigin('*',cdstCacheStorage) has the same function of GlobalCEFApp.DeleteCache, because in network tab of DevTools, some lines of the size column shows ‘(disk cache)' after calling ClearDataForOrigin, however, it shows like XXKB after calling DeleteCache. How to prove it?

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Tue Jul 26, 2022 8:06 am
by salvadordf
GlobalCEFApp.DeleteCache deletes almost all files inside the cache directory. Those files include the app cache, shader cache, local storage, etc.
It's a crude but effective way to delete almost everything in the browser cache directory.

TChromiumCore.ClearDataForOrigin on the other hand deletes only what you select from the domain you want. This function uses the "Storage.clearDataForOrigin" DevTools method instead of deleting files. Consider this a precision tool that uses internal Chromium functions to complete the task.
https://chromedevtools.github.io/devtools-protocol/tot/Storage/#method-clearDataForOrigin

Re: GlobalCEFApp.DeleteCache will delete cookies too

Posted: Wed Jul 27, 2022 8:38 am
by tad.chen
Thank you for your information.

I test again and find that in CEF 7X, calling GlobalCEFApp.DeleteCache will not delete cookies, but in CEF 9X, it will.