Skip to content

Instantly share code, notes, and snippets.

@h3h
Last active December 9, 2015 00:08
Show Gist options
  • Save h3h/a3c6c2477635d1221ad1 to your computer and use it in GitHub Desktop.
Save h3h/a3c6c2477635d1221ad1 to your computer and use it in GitHub Desktop.
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