SHARE
TWEET

Untitled

a guest May 16th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Clears the storage of a website
  3.  * "Just like" as Chrome DevTools, but with pure JavaScript
  4.  */
  5. (async () => {
  6.     async function clearIndexedDB (iDB) {
  7.         const databases = await iDB.databases();
  8.        
  9.         for (let database of databases) {
  10.             iDB.deleteDatabase(database);
  11.         }
  12.     }
  13.  
  14.     function clearStorage (storage) {
  15.         storage.clear();
  16.     }
  17.  
  18.     function clearCookies (doc) {
  19.         doc.cookie = '';
  20.     }
  21.  
  22.     async function unregisterServiceWorkers (serviceWorker) {
  23.         const registrations = await serviceWorker.getRegistrations();
  24.  
  25.         for (let registration of registrations) {
  26.             registration.unregister();
  27.         }
  28.     }
  29.  
  30.     function refreshPage (location) {
  31.         location.reload();
  32.     }
  33.  
  34.     await clearIndexedDB(indexedDB);
  35.     clearStorage(localStorage);
  36.     clearStorage(sessionStorage);
  37.     clearCookies(document);
  38.     await unregisterServiceWorkers(navigator.serviceWorker);
  39.  
  40.     refreshPage(window.location);
  41. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top