Created
July 6, 2026 04:47
-
-
Save sumonst21/e063267a11d931d6643eb89ee37af261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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