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.

GlobalCEFApp.DeleteCache will delete cookies too

Post Reply
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

GlobalCEFApp.DeleteCache will delete cookies too

Post by tad.chen »

I find that calling GlobalCEFApp.DeleteCache in the initialization of browser will delete cookies too. I uses ceflib 9X, Why?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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);
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post by salvadordf »

The latest CEF4Delphi version at GitHub includes the fix for this issue.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: GlobalCEFApp.DeleteCache will delete cookies too

Post 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.
Post Reply