I have built an electron app that allows the user to move elements such as divs around the screen, and saves their locations in localstorage as a class. This is so when the page reloads or is reopened after a session, the changes made persist. I can't get electron to access the local storage though, even on a page change, so I was wondering if there is anyway to make electron go and grab the localstorage classes, or if I can make the page itself do it.
localStorage Web API. This package is compliant and works without any errors as of Electron v8. 3.0 and it is regularly updated.
localStorage is quite insecure as it has no form of data protection and can be accessed by any code on your web page.
As local storage was never intended to be secure, there is no data protection and any JavaScript on the website can access it. Hackers can exploit the existing XSS vulnerability on the website like the following screenshot when the user browses to https://set-localstorage.herokuapp.com/xss-injected-page.html.
You can read data from localstorage. Here is what work for me.
mainWindow.webContents
.executeJavaScript('localStorage.getItem("thekey");', true)
.then(result => {
console.log(result);
});
You gets the entire localStorage and use it as you would do it in a browser. The localStorage variable now is an object with key-values.
mainWindow.webContents
.executeJavaScript('({...localStorage});', true)
.then(localStorage => {
console.log(localStorage);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With