storage.estimate Reports Quota Headroom
StorageManager.estimate() returns usage and quota for the origin, and persisted() reads whether storage survives eviction pressure.
Code
// StorageManager.estimate() reports origin usage and quota asynchronously
const manager = navigator.storage;
if (!manager || typeof manager.estimate !== 'function') {
console.log('StorageManager unavailable in this context');
} else {
const { usage = 0, quota = 0 } = await manager.estimate();
const used = (usage / 2 ** 20).toFixed(1);
const cap = (quota / 2 ** 20).toFixed(1);
const headroom = ((quota - usage) / 2 ** 20).toFixed(1);
console.log('used MB:', used, '| quota MB:', cap, '| headroom MB:', headroom);
// persisted() reads whether the origin already keeps storage under pressure
const persisted = await manager.persisted();
console.log('persisted storage:', persisted);
}Output
Captured from a sandboxed run of this snippet in the build pipeline.
StorageManager unavailable in this contextHow it works
The code’s whole job belongs to the functions used, cap and headroom.
The async parts await their results, which keeps ordering predictable.
What to watch for
- It runs on exactly what the toolchain already ships — nothing extra.
- This is browser-side code —
navigatorwill not resolve in Node.
Putting it to use
The signature you will call most reads const used = (usage / 2 ** 20)
Output lines are prefixed (StorageManager unavailable in this context, used MB:, persisted storage:), so each step’s effect shows up clearly in the output.
Core lines
const { usage = 0, quota = 0 } = await manager.estimate();
const persisted = await manager.persisted();
Interactive Tools for This Topic
Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.DOM Event Propagation VisualizerVisualize DOM event capturing, targeting, and bubbling phases in real time. Toggle stopPropagation and stopImmediatePropagation to see how events traverse the tree.INI File ParserParse INI configuration files into nested JSON with section objects, global keys, and both semicolon and hash comment support.JSON to TOML ConverterTurn a JSON object into TOML, emitting nested objects as tables and arrays of objects as array-of-tables blocks.
FAQ
- Does this require external packages?
- No. It relies only on built-in language and platform APIs, so you can paste it into a project without installing anything. The file defines `used`, `cap`, `headroom` at load time.
Report a problem with this exampleOpens a pre-filled issue on GitHub.