How to keep the user settings across different Puppeteer Core sessions

Posted on October 6, 2021

If you want to keep the user settings across different Puppeteer Core sessions, for instance, keep the same localStorage or cookies for authentication purposes, you can set a local user folder in the launch configuration options:

const puppeteer = require('puppeteer-core')

let launchOptions = { 
  executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
  headless: true,
  args: [
    '--user-data-dir=/Users/username/some/folder/user'
  ]
}

const browser = await puppeteer.launch(launchOptions)
const page = await browser.newPage()