如何在 Mac 上的 Puppeteer 中加载 Chrome?

bib*_*scy 4 node.js puppeteer

为什么我的浏览器无法加载 Chrome?我收到错误:

该消息是无法启动浏览器进程!生成 /Applications/GoogleChrome.app ENOENT 故障排除: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

节点版本 v13.12.0

 const browser = await puppeteer.launch({executablePath:'/Applications/Google\Chrome.app'});
 const page = await browser.newPage();
 await page.goto('https://my.gumtree.com/login', {waitUntil: 'networkidle2'});
 const myButton = await page.$('#google-sign-in-button');
 myButton.click();
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

had*_*oop 7

如果您想使用已安装的 chronium 启动 puppeteer,则需要设置executablePath. 所以请检查chronium的确切路径。

  1. chrome://version/在 Chrome 中浏览。
  2. 然后,你可以找到executablePath.
  3. 确保您写了正确的路径。

const browser = await puppeteer.launch({executablePath:'your executable Path'});
const page = await browser.newPage();
await page.goto('https://my.gumtree.com/login', {waitUntil: 'networkidle2'});
const myButton = await page.$('#google-sign-in-button');
myButton.click();
Run Code Online (Sandbox Code Playgroud)