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.

Observe localStorage changes

Post Reply
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Observe localStorage changes

Post by xpert13 »

Hello.

I need to save all localStorage changes to my own database. is it any way to observe all changes of the localStorage? (Something line OnCanSaveCookie for cookies)
User avatar
salvadordf
Posts: 4059
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Observe localStorage changes

Post by salvadordf »

Hi,

Perhaps you can do that with the DevTools methods and events but I haven't tried it.

Try the "Storage Domain" and "DOMStorage Domain" methods and events :
https://chromedevtools.github.io/devtoo ... t/Storage/
https://chromedevtools.github.io/devtoo ... OMStorage/
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Re: Observe localStorage changes

Post by xpert13 »

How can I use DevTools methods and events in CEF4Delphi? I found it in DevTools but I don't understand how can I use this events in my code.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Observe localStorage changes

Post by dilfich »

xpert13 wrote: Tue Sep 08, 2020 4:37 pm How can I use DevTools methods and events in CEF4Delphi? I found it in DevTools but I don't understand how can I use this events in my code.
Look in the sources for methods for clearing the cache \ storage.

Code: Select all

Chromium1.ExecuteDevToolsMethod(0, 'Network.clearBrowserCache', nil);
User avatar
salvadordf
Posts: 4059
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Observe localStorage changes

Post by salvadordf »

As dilfich said, there are some code examples in TChromiumCore and also in some demos like DOMVisitor or MiniBrowser.

In this case I suppose you would have to do this for the "Storage Domain" :
  • Call TChromium.ExecuteDevToolsMethod with a "Storage.trackCacheStorageForOrigin" method parameter and the origin you wish to track.
    https://chromedevtools.github.io/devtoo ... eForOrigin
  • Implement TChromium.OnDevToolsEvent to handle the "Storage.cacheStorageContentUpdated" event.
For the "DOMStorage Domain" you would have to :
  • Call TChromium.ExecuteDevToolsMethod with a "DOMStorage.enable" parameter.
  • Implement TChromium.OnDevToolsEvent to handle all the "DOMStorage Domain" events : DOMStorage.domStorageItemAdded, DOMStorage.domStorageItemRemoved, DOMStorage.domStorageItemsCleared, DOMStorage.domStorageItemUpdated.
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Re: Observe localStorage changes

Post by xpert13 »

Thank you guys! It's what I was looking for.
Post Reply