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.

Clear local storage ?

Post Reply
thefunkyjoint
Posts: 461
Joined: Thu Aug 10, 2017 12:40 pm

Clear local storage ?

Post by thefunkyjoint »

Is there a command on CEF4Delphi to clear just the local storage (not cookies) of the current url ?

I mean that part on Devtools :

https://ibb.co/QYTmQR6
User avatar
salvadordf
Posts: 4086
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Clear local storage ?

Post by salvadordf »

Yes. You can call TChromiumCore.ClearDataForOrigin with these parameters :
  • aOrigin : Security origin. An asterisk * means all origins.
  • aStorageTypes :
    • cdstAppCache : app cache
    • cdstCookies : cookies
    • cdstFileSystems : file systems
    • cdstIndexeddb : indexed db
    • cdstLocalStorage : local storage
    • cdstShaderCache : shader cache
    • cdstWebsql : websql
    • cdstServiceWorkers : service workers
    • cdstCacheStorage : cache storage
    • cdstAll : all of the above.
That function calls the Storage.clearDataForOrigin DevTools method :
https://chromedevtools.github.io/devtools-protocol/tot/Storage/#method-clearDataForOrigin

This is an asynchronous function and you have to wait for the TChromiumCore.OnDevToolsMethodResult event to know the result.
thefunkyjoint
Posts: 461
Joined: Thu Aug 10, 2017 12:40 pm

Re: Clear local storage ?

Post by thefunkyjoint »

Thank you :D
thefunkyjoint
Posts: 461
Joined: Thu Aug 10, 2017 12:40 pm

Re: Clear local storage ?

Post by thefunkyjoint »

I've made some tests and looks like i need to call the function like this :

ClearDataForOrigin('cdstLocalStorage',cdstLocalStorage);

Passing two parameters otherwise it will delete everything, including cookies. Is this correct ?
User avatar
salvadordf
Posts: 4086
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Clear local storage ?

Post by salvadordf »

Use a URL as origin in the first parameter like this :

Code: Select all

TChromiumCore.ClearDataForOrigin('https://www.google.com', cdstLocalStorage);
If you navigate to https://www.google.com you will see an entry in the local storage. The previous code deletes that entry and leaves the cookies unchanged.
thefunkyjoint
Posts: 461
Joined: Thu Aug 10, 2017 12:40 pm

Re: Clear local storage ?

Post by thefunkyjoint »

Now i understood, the first parameter is the url. Thanks !
Post Reply