Puppeteer 无法使用 Chromium 在无头模式下工作

COL*_*pto 5 google-chrome chromium raspberry-pi puppeteer

我在运行 Raspbian 10 的 Raspberry pi 上使用 Puppeteer 1.20.0 和 Chromium-browser v74。在禁用无头模式下运行 Puppeteer 时,使用 Puppeteer Github 页面中的示例代码可以按预期工作,但是,如果我尝试在无头模式下运行它,我会收到此错误并且崩溃。

UnhandledPromiseRejectionWarning:错误:导航失败,因为浏览器已断开连接。

我的代码:

const puppeteer = require('puppeteer-core');

(async () => {
    const browser = await puppeteer.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        executablePath: '/usr/bin/chromium-browser',
        headless: true
    });
  const page = await browser.newPage();
  await page.goto('https://youtube.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

相同的代码在另一台 Debian 10 机器上的无头和非无头都能按预期工作。它们都运行 Puppeteer 1.20.0,唯一的区别是 Debian 机器运行 Google-chrome 77,而 Raspbian 运行 Chromium-browser 74。

编辑:

我还尝试了 puppeteer-core 版本 1.13.0,这是 chromium 74 的推荐版本,但它在无头模式下也不起作用。

Kyl*_*yle 0

Puppeteer 仅保证可以与它捆绑的 chromium 版本一起使用(puppeteer 而不是 puppeteer-core)。因此,运行为 chromium 74 构建的旧版本 puppeteer 可能会有更好的运气。