MacOS下Puppeteer启动Chrome配置文件失败报错求助
问题:Puppeteer启动Chrome配置文件时进程启动失败
错误信息
file:///Users/cheng/Workspace/web3/puppeteer/node_modules/@puppeteer/browsers/lib/esm/launch.js:301 reject(new Error([ ^ Error: Failed to launch the browser process! TROUBLESHOOTING: https://pptr.dev/troubleshooting at ChildProcess.onClose (file:///Users/cheng/Workspace/web3/puppeteer/node_modules/@puppeteer/browsers/lib/esm/launch.js:301:24) at ChildProcess.emit (node:events:531:35) at ChildProcess._handle.onexit (node:internal/child_process:294:12) Node.js v21.7.1
实现代码
import puppeteer from 'puppeteer'; (async () => { const browser = await puppeteer.launch({ headless: false, executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", args: [ '--user-data-dir=/Users/cheng/Library/Application Support/Google/Chrome', '--profile-directory=Profile 7', '--no-sandbox', '--disable-setuid-sandbox' ], }); const page = await browser.newPage(); await page.goto('https://developer.chrome.com/'); await page.setViewport({ width: 1080, height: 1024 }); })();
解决方法
- 关闭正在运行的Chrome实例:如果目标配置文件(Profile 7)已被当前打开的Chrome占用,Puppeteer无法启动新进程,先关闭所有Chrome窗口再重试。
- 调整用户数据目录权限:确保
/Users/cheng/Library/Application Support/Google/Chrome目录及子目录有读写权限,可通过终端执行chmod -R 755 /Users/cheng/Library/Application\ Support/Google/Chrome修改。 - 验证配置文件路径:手动打开Chrome,通过
chrome://version/查看当前配置文件的实际路径,确认和代码中的Profile 7路径一致。 - 添加额外启动参数:尝试加入
--disable-dev-shm-usage解决共享内存限制问题,或--single-process强制单进程启动(仅用于调试)。 - 使用Puppeteer自带Chrome:删除
executablePath配置,让Puppeteer使用内置Chrome版本,避免本地Chrome与Puppeteer版本不兼容。
内容的提问来源于stack exchange,提问作者cheng
相关产品推荐
相关产品推荐

