Created
August 11, 2020 19:14
-
-
Save gokusenz/4b65375df1bfd93b8407c11072face2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const restoreLocalStorage = async () => { | |
let json = JSON.parse(fs.readFileSync(`${__dirname}/local.json`)); | |
await page.evaluate(json => { | |
localStorage.clear(); | |
for (let key in json) | |
localStorage.setItem(key, json[key]); | |
}, json); | |
} | |
const saveLocalStorage = async () => { | |
console.log("saving"); | |
const json = await page.evaluate(() => { | |
let json = {}; | |
for (let i = 0; i < localStorage.length; i++) { | |
const key = localStorage.key(i); | |
json[key] = localStorage.getItem(key); | |
} | |
return json; | |
}); | |
console.log(json); | |
fs.writeFileSync(`${__dirname}/local.json`, JSON.stringify(json)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment