How to delete local storage when uninstalling an electron app which uses squirrel
Asked Answered
U

1

7

I have an electron.js application where I am trying to clear the local storage of the application on uninstalling the application. The application's installer/uninstaller depends Squirrel.Windows. I have tried the following code using electron.session on --squirrel-uninstall event, but that does not work

try {
  // clear storage data on uninstall
  const defaultSession = session.defaultSession;
  defaultSession.clearStorageData();
  defaultSession.clearCache()
} catch (e) {
  console.log(e);
}

Any help will be highly appreciated.

Unbidden answered 9/2, 2017 at 5:20 Comment(1)
I have the same question, have you gotten this clear?Gooseneck
B
0

The only thing that worked for me was this code:

const sessionDataFolder = app.getPath(`sessionData`);
const localStorageFolder = path.join(sessionDataFolder, `Local Storage`);

await fs.rm(localStorageFolder, { force: true, recursive: true });

I also tried the session.defaultSession.clearStorageData() or instantiating an invisible BrowserWindow object and doing window.webContents.session.clearStorageData() or even calling window.webContents.executeJavaScript("localStorage.clear();", true); but any interaction with session or window.webContents ended up with the app to immediately exit without any exceptions.

Bipack answered 7/3 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.