Skip to content

Instantly share code, notes, and snippets.

@gokusenz
Created March 5, 2020 09:43
Show Gist options
  • Save gokusenz/5edc970bf14cc3be2be1babea7d2ff09 to your computer and use it in GitHub Desktop.
Save gokusenz/5edc970bf14cc3be2be1babea7d2ff09 to your computer and use it in GitHub Desktop.
How to save cookies and load it in another puppeteer session?
// Save cookies to disk
const fs = require('fs').promises;
// ... puppeteer code
const cookies = await page.cookies();
await fs.writeFile('./cookies.json', JSON.stringify(cookies, null, 2));
// Resue cookies
const fs = require('fs').promises;
// ... puppeteer code
const cookiesString = await fs.readFile('./cookies.json');
const cookies = JSON.parse(cookiesString);
await page.setCookie(...cookies);
// Ref : https://stackoverflow.com/questions/56514877/how-to-save-cookies-and-load-it-in-another-puppeteer-session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment