Public
Edited
Feb 25, 2023
Insert cell
Insert cell
Insert cell
checkStorage()
Insert cell
async function checkStorage() {
if (!navigator) {
return `No navigator access`;
}
if (!navigator.storage) {
return `No navigator.storage access`;
}
if (!navigator.storage) {
return `No navigator.storage access`;
}
if (!navigator.storage.estimate) {
return `No navigator.storage.estimate function.`;
}
const quota = await navigator.storage.estimate();
// quota.usage -> Number of bytes used.
// quota.quota -> Maximum number of bytes available.
const percentageUsed = (quota.usage / quota.quota) * 100;
const remaining = quota.quota - quota.usage;
return md`navigator.storage.estimate() returned<br>${JSON.stringify(quota)}:
- Your quota is ${(quota.quota/1024/1024).toLocaleString(3)} MB.
- You've used ${(quota.usage/1024/1024).toLocaleString(3)} MB, ${percentageUsed.toFixed(2)}% of the available storage.
- You can write up to ${(remaining/1024/1024).toLocaleString(3)} more MB.`
};
Insert cell
localStorage.setItem("test","x".repeat(1024*1024*4))
Insert cell
localStorage.getItem("test").length
Insert cell
//localStorage.clear()
Insert cell
localStorage.length
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more