Advertisement
Advanced JavaScript, Browser Storage & Web APIs

How do you check available and used storage quota in a browser?

Short answer

Use the StorageManager API's navigator.storage.estimate(), which returns a Promise resolving to an object with usage and quota (both in bytes), covering localStorage, IndexedDB, Cache API, and other origin storage combined.

Save JavaScript mock interview
Advertisement
AModel answer
Use the StorageManager API's navigator.storage.estimate(), which returns a Promise resolving to an object with usage and quota (both in bytes), covering localStorage, IndexedDB, Cache API, and other origin storage combined.
const { usage, quota } = await navigator.storage.estimate();
console.log(`Using ${usage} of ${quota} bytes`);
Real-world example
Warning users before an offline-capable app runs out of storage space for cached data.
Likely follow-ups
  • What is navigator.storage.persist() used for?
Related topics