How can I or my app know that Chrome is discarding indexed db items? How can I or my app know that Chrome is discarding indexed db items? google-chrome google-chrome

How can I or my app know that Chrome is discarding indexed db items?


Each application can query how much data is stored or how much more space is available for the app by calling queryUsageAndQuota() method of Quota API.See

You can use periodic BackgroundSyncto estimate the used and free space allocated to temporary usage using:

// index.htmlnavigator.serviceWorker.ready.then(registration => {  registration.periodicSync.register('estimate-storage', {    // Minimum interval at which the sync may fire.    minInterval: 24 * 60 * 60 * 1000,  });});// service_worker.jsself.addEventListener('periodicsync', event => {  if (event.tag == 'estimate-storage') {    event.waitUntil(estimateAndNotify());  }});To estimate use the method: navigator.storage.estimate()//returns a Promise which resolves with {usage, quota} values in bytes. 

When TEMPORARY storage quota is exceeded, all the data (incl. AppCache, IndexedDB, WebSQL, File System API) stored for oldest used origin gets deleted.

You can switch to unlimitedStorage or persistent storage.


Not sure how will it work in real life

This feature was initially still somewhat experimental.

but here https://developers.google.com/web/updates/2016/06/persistent-storage you can find that

This is still under development [...] the goal is to make users are aware of “persistent” data before clearing it [...] you can presume that “persistent” means your data won’t get cleared without the user being explicitly informed and directly in control of that deletion.

Which can answer you clarification in comments that you are looking for a way

how can a user or my app know for sure that this is happening

So, don't know about your app, but user maybe can get a notification. At least the page is of 2016 year. Something must have been done by now.


You may refer to Browser storage limits and eviction criteria article on MDN.

My hypothesis is that Chrome is discarding indexeddb items because the disk is full

According to this article your hypothesis seems to be true.

Now one of the ways to confirm this could be to save unique ids of items that are confirmed in a persistent storage - (this will have very small size compared to your actual data) and periodically compare whether all items are there in your indexeddb.

You might also want to refer to best practices.and finally this comments

I think you need IndexedDB Observer. These links may help you if I got what you meant. Link-01 - Link-02

might be helpful.