Skip to content

Instantly share code, notes, and snippets.

@h3h h3h/maxLocalStorage.js
Last active Dec 9, 2015

Embed
What would you like to do?
Fill up localStorage completely on a given page.
var DATA = [
'0',
'0000000000',
'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
];
var chunkSize, i, printFactor;
var chunkIndex = (DATA.length - 1);
while (chunkIndex >= 0) {
try {
chunkSize = DATA[chunkIndex].length;
i = 0;
printFactor = Math.pow(10, 5 - Math.log10(chunkSize));
console.log("Filling your localStorage up with %d-byte chunks...", chunkSize);
while (++i) {
window.localStorage['garbage'+i] = DATA[chunkIndex];
if (i % printFactor == 0) {
console.log("%d chunks saved to localStorage for this chunk size.", i);
}
}
} catch (e) {
if (chunkIndex == 0) {
console.log("All full: %s", e);
}
chunkIndex--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.