Can Puppeteer store values from sessionStorage and localStorage on a disk and use them next time?
To keep your connection alive, is as easy as adding keepalive=<MILLISECONDS> to the query string on your connection. Assuming you're self-hosting: const innit = async () => { const browser = await puppeteer. connect({ browserWSEndpoint: 'ws://localhost:3000?keepalive=300000' }); const page = await browser.
If you want to store structured data on the client side, IndexedDB is the better choice, especially since localStorage isn't built to store sensitive information. But if you're storing a simple, small amount of key-value pair data, use localStorage.
Right, sessionStorage is not shared across tabs. The way I solved it is by using localStorage events. When a user opens a new tab, we first ask any other tab that is opened if he already have the sessionStorage for us.
I was looking for the same thing. I used node-persist together with Puppeteer as a solution. You can use it like the following.
const storage = require('node-persist');
// Set Local Storage
storage.initSync();
var data = {
"token": storage.getItemSync("token")
};
page.evaluate((data) => {
localStorage.setItem("token", data.token);
}, data);
// Get Local Storage
page.evaluate(() => {
return {
"token": localStorage.getItem("token")
};
}).then((data) => {
storage.initSync();
storage.setItemSync("token", data.token);
});
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