Skip to content

Instantly share code, notes, and snippets.

@davesheffer
Last active March 6, 2024 10:50
Show Gist options
  • Save davesheffer/8a144b5d596c11b0895de5b7d9767b4a to your computer and use it in GitHub Desktop.
Save davesheffer/8a144b5d596c11b0895de5b7d9767b4a to your computer and use it in GitHub Desktop.
Clear Site Data
var theCookies = document.cookie.split(';');
for (var i = 1 ; i <= theCookies.length; i++) {
var acookie = theCookies[i-1];
var cookieArr = acookie.split('=');
console.log(cookieArr[0]);
document.cookie = cookieArr[0]+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
// Get cache storage and clear cache storage
window.caches.keys().then(function(names) {
for (let name of names)
window.caches.delete(name);
});
// Get indexed db and delete indexed db
const dbs = await window.indexedDB.databases()
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) })
// clear localStorage
window.localStorage.clear();
// clear sessionStorage
window.sessionStorage.clear();
@davesheffer
Copy link
Author

Clear Site Data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment