The Storage Manager
navigator.storage
Section titled “navigator.storage”The navigator.storage object is the entry point to the Storage Manager API. It gives you visibility into how much disk space the current origin is consuming, what quota the browser has granted, and whether the origin’s data is protected from eviction.
All three methods are async and return Promises.
navigator.storage.estimate()
Section titled “navigator.storage.estimate()”Returns a Promise that resolves to an object with two properties:
usage— the number of bytes currently used by the origin across all storage mechanisms (Cache API, IndexedDB, localStorage, etc.)quota— the maximum number of bytes the browser is willing to grant to this origin
Both values are in bytes and are estimates. The browser may round or cap them for privacy reasons.
const { usage, quota } = await navigator.storage.estimate();
const usageMB = (usage / 1024 ** 2).toFixed(2);const quotaMB = (quota / 1024 ** 2).toFixed(2);
console.log(\`Used: \${usageMB} MB of \${quotaMB} MB available\`);Quota is dynamic — it varies based on how much free space is available on the device. On mobile devices with limited storage, the quota may be much smaller than on desktop machines.
navigator.storage.persist()
Section titled “navigator.storage.persist()”Requests that the browser grant persistent storage to the current origin. Returns a Promise that resolves to true if the request was granted, or false if the browser declined.
const granted = await navigator.storage.persist();console.log('Persistent storage granted:', granted);Whether the browser grants persistence depends on browser heuristics, such as whether the user has added the site to their home screen, how often the user visits, or whether the user explicitly approved a permission prompt. You cannot force it to return true.
navigator.storage.persisted()
Section titled “navigator.storage.persisted()”Checks whether the current origin already has persistent storage. Returns a Promise that resolves to true if storage is currently persistent, or false if it is best-effort.
const isPersistent = await navigator.storage.persisted();
if (isPersistent) { console.log('Data is safe from automatic eviction');} else { console.log('Data may be evicted under storage pressure');}Use persisted() at app startup to determine whether you need to show a “please allow persistent storage” prompt to the user.