How to pass userDataDir profile folder to Puppeteer

情到浓时终转凉″ 提交于 2019-12-13 00:02:18

问题


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


回答1:


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:

puppeteer.launch({ userDataDir: './myUserDataDir', })



来源:https://stackoverflow.com/questions/46908441/how-to-pass-userdatadir-profile-folder-to-puppeteer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!