12

I want to pass a custom profile to Puppeteer. To start I've tried to pass my real Google Chrome profile:

const browser = await puppeteer.launch({
  userDataDir: '/Users/[USERNAME]/Library/Application Support/Google/Chrome/Default',
  headless: false,
  slowMo: 250,
  ...
}

but when the browser opens if I go to Settings it shows Person 1 rather than the data from my Google Chrome profile

The userDataDir path above is what is shown in Profile Path when on Google Chrome I visit chrome://version (where [USERDATA] is my username)

I've tried also userDataDir: '~/Library/Application Support/Google/Chrome/Default'

I'm using
Puppeteer 0.11.0
Node 8.4.0
NPM 5.2.0
macOS El Capitan 10.11.6
MacBook Pro Retina, 15-inch, Mid 2015

Giorgio
  • 13,129
  • 12
  • 48
  • 75

2 Answers2

17

Using a relative path worked. The path is relative to the folder where you are executing the cli command running the javascript that uses puppeteer:

await puppeteer.launch({
  userDataDir: './myUserDataDir',
})
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Giorgio
  • 13,129
  • 12
  • 48
  • 75
  • I tried the solution it is giving the below error [9665:775:0117/220533.630257:ERROR:browser_dm_token_storage_mac.mm(153)] Error retrieving the machine serial number. – ifelse.codes Jan 17 '19 at 16:36
  • 2
    that didn't work! this still creating new temp profile. – Code Cooker Apr 29 '20 at 03:40
  • 1
    try to play with path.resolve(__dirname, './myUserDataDir') – Giorgio Apr 29 '20 at 15:08
  • I still couldn't get it to work. Turns out the code I inherited included default args were sent to puppeteer. These default args already a default user-data-dir in that points to the temp folder, which came first so Chrome was using the temp dir even though I was specifying something different. I couldn't change the defaults around so the fix I found was to use userDataDir direct with puppeteer.launch, which takes precedence over the args. Using chrome://version was very useful debugging which profile directory is being used. – Adam Dec 16 '22 at 04:16
0
await puppeteer.launch({
  userDataDir: 'myUserDataDir',
})

try using this, it will create a directory automatically.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 20 '23 at 03:39