This document proposes an addition to the Storage API (specifically the Storage Manager interface) that would allow script to asynchronously request an estimation of quota usage broken down by storage backend.
There have been frequent requests from users of navigator.storage.estimate()
to provide a per-storage system breakdown estimate.
Currently, a call to this function yields only an estimate of the quota usage for all storage systems combined, making it difficult for developers to reason about what is using up quota.
For example, consider an email client that uses IndexedDB to store text and Cache Storage to store attachments. If this client had a pattern of high Cache Storage usage, but low IndexedDB usage, a developer might be able to determine that the app forgot to delete attachments when evicting messages from the local cache. If there were high usage for both storage backends, this might mean the app is caching too many messages, suggesting the eviction policy is not behaving correctly.
By providing a more detailed breakdown of how storage is being used, the change proposed below will allow developers to make these assessments.
Currently, StorageManager.estimate()
asynchronously provides a StorageEstimate
object with two fields, usage
and quota
.
usage
reflects how many bytes a given origin is effectively using for same-origin data, which in turn can be impacted by internal compression techniques, fixed-size allocation blocks that might include unused space, and the presence of “tombstone” records that might be created temporarily following a deletion.
quota
reflects the amount of space currently granted to an origin.
QuotaExceededError
if usage would increase past quota.Within origin-scoped data, a subset is quota-managed data accounted for by the Quota Manager
The proposed change adds another member, usageDetails
, to the StorageEstimate
dictionary returned by navigator.storage.estimate()
. This new dictonary will contain key-value pairs showing the usage of each storage system, where the keys are the names of the storage systems and the value is an estimate, in bytes, of how much disk space said system is using.
Figure 1: Example use of the API from the Chrome devtools console, demonstrating that usageDetails mirrors devtools' usage report.
usageDetails.caches + usageDetails.indexedDB
which, if the usage for either of those was 0, would return NaN
. Instead, developers would have to be defensive and write something like (usageDetails.caches || 0) + (usageDetails.indexedDB || 0)
.usageDetails
members.
other
property on usageDetails
that’s literally total - Sum(usageDetails)
.DOMStorage
(localStorage
) is not counted in the quota. This can be addressed via documentation rather than a change to the API shape.Per-system quota usage (IndexedDB vs Cache Storage vs AppCache etc.) is a function of all calls made by an origin to the respective storage APIs. The numbers summarize information that the origin already has. An origin can monitor the change in total quota with every storage API call to keep a running total.
An origin that has data stored on the client (non-zero quota usage) can store a unique identifier for the user. Instead of using this new API, the origin can simply read a user ID from IndexedDB, or from Cache Storage etc. In other words, the new API does not make it any easier to identify or track users.