Skip to content

Instantly share code, notes, and snippets.

@sumonst21
Created July 6, 2026 04:47
Show Gist options
  • Select an option

  • Save sumonst21/e063267a11d931d6643eb89ee37af261 to your computer and use it in GitHub Desktop.

Select an option

Save sumonst21/e063267a11d931d6643eb89ee37af261 to your computer and use it in GitHub Desktop.
/**
* @name BrowserStorageAudit
* @version 1.0.0
* @description This script audits the browser's storage mechanisms to identify potential sources of large data usage, particularly focusing on Cache Storage, IndexedDB, LocalStorage, and SessionStorage. It logs the findings to the console for easy inspection.
* @author sumonst21
*/
(async () => {
console.log("%c--- STARTING BROWSER STORAGE AUDIT ---", "color: #00ff00; font-weight: bold;");
// 1. Audit Cache Storage API (Most likely culprit for video chunks)
if ('caches' in window) {
try {
const cacheNames = await caches.keys();
if (cacheNames.length === 0) {
console.log("πŸ“‚ Cache Storage: No caches found.");
} else {
console.log(`πŸ“‚ Cache Storage: Found ${cacheNames.length} cache containers.`);
for (const name of cacheNames) {
const cache = await caches.open(name);
const requests = await cache.keys();
console.log(` └─ Cache Name: "${name}" (${requests.length} items cached)`);
// Sample the first 5 URLs to see what kind of files they are
if (requests.length > 0) {
console.log(" 🟒 Sample URLs stored here:");
requests.slice(0, 5).forEach(req => console.log(` β€’ ${req.url}`));
if (requests.length > 5) console.log(` β€’ ... and ${requests.length - 5} more items.`);
}
}
}
} catch (e) {
console.error("❌ Error reading Cache Storage:", e);
}
}
// 2. Audit IndexedDB
if ('indexedDB' in window) {
try {
// Note: Modern browsers don't allow easily listing all IDB databases asynchronously
// without webkitGetDatabaseNames (deprecated), but we can check databases registered via modern API
if (indexedDB.databases) {
const dbs = await indexedDB.databases();
if (dbs.length === 0) {
console.log("πŸ’Ύ IndexedDB: No databases found.");
} else {
console.log(`πŸ’Ύ IndexedDB: Found ${dbs.length} databases.`);
dbs.forEach(db => {
console.log(` └─ Database: "${db.name}" (Version: ${db.version})`);
});
}
} else {
console.log("πŸ’Ύ IndexedDB: API available, but database listing not supported via console script.");
}
} catch (e) {
console.error("❌ Error reading IndexedDB:", e);
}
}
// 3. Audit LocalStorage & SessionStorage (Highly unlikely to be GBs, but good to check)
const lsSize = Object.keys(localStorage).reduce((acc, key) => acc + (localStorage[key].length || 0), 0);
console.log(`πŸ“Š LocalStorage Approximate Data Size: ${(lsSize / 1024 / 1024).toFixed(2)} MB`);
console.log("%c--- AUDIT COMPLETE ---", "color: #00ff00; font-weight: bold;");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment