问题描述
我想将自定义配置文件传递给Puppeteer。
首先,我尝试通过真实的Google Chrome个人资料:
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,
...
}
但是当我打开浏览器设置打开浏览器时,它会显示 Person 1
而不是我的Google Chrome个人资料中的数据
but when the browser opens if I go to Settings it shows Person 1
rather than the data from my Google Chrome profile
上面的userDataDir路径就是个人资料路径中显示的内容
在Google Chrome上访问时,我访问 chrome:// version
(其中[USERDATA]是我的用户名)
The userDataDir path above is what is shown in Profile Path
when on Google Chrome I visit chrome://version
(where [USERDATA] is my username)
我也尝试过userDataDir:'〜/ Library / Application Support / Google / Chrome / Default'
I've tried also userDataDir: '~/Library/Application Support/Google/Chrome/Default'
我正在使用
Puppeteer 0.11.0
节点8.4.0
NPM 5.2.0
macOS El Capitan 10.11.6
MacBook Pro视网膜, 15英寸,2015年中
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
推荐答案
使用相对路径有效。该路径是相对路径到执行cli命令并运行使用puppeteer的javascript的文件夹:
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',
})
这篇关于如何将userDataDir配置文件文件夹传递给Puppeteer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!