google-chrome - Puppeteer 无法使用 Chrome 在 headless 模式下工作

标签 google-chrome raspberry-pi chromium puppeteer

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

UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected.



我的代码:
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();
})();

在另一台 Debian 10 机器上,相同的代码在 headless 和非 headless 的情况下都可以正常工作。他们都在运行 Puppeteer 1.20.0,唯一的区别是 Debian 机器运行的是 Google-chrome 77,而 Raspbian 运行的是 Chromium-browser 74。

编辑:

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

最佳答案

我终于能够运行 puppeteer ......但不能在 Raspbian buster 上运行。以下是我成功运行 puppeteer 的环境的详细信息:

  • Linux raspberrypi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux
  • Raspbian Stretch (2019-04-08-raspbian-stretch)
  • NodeJS v12.10.0 和 npm v6.10.3(来自 nodesource)
  • puppeteer-core@1.11.0
  • chromium-browser Chrome 72.0.3626.121 基于 Raspbian 构建,在 Raspbian 9.11
  • 上运行

    我没有使用从 puppeteer 下载的 Chrome ,我使用了 raspbian 附带的那个并添加了 "executablePath"配置所以我只能使用 "puppeteer-core"

    关于google-chrome - Puppeteer 无法使用 Chrome 在 headless 模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58122373/

    相关文章:

    javascript - 使用视频源作为 Canvas 视频轨道的 OpenTok 问题 - Google Chrome 66

    html - 为什么 Chrome 会向我的页面添加额外的 html?

    google-chrome - chrome.tabs 问题与 chrome.tabs.update 和 chrome.tabs.executeScript

    PHP exec() 无法在 Raspberry apache 服务器上运行

    raspberry-pi - 如果在 Kivy 中反转触摸输入怎么办

    CSS 3D 转换在 Chrome 26 (Ubuntu 12.04) 上不起作用

    javascript - Chromium忽略css样式或属性高度中的表格高度

    html - ubuntu chromium 错误的 html 渲染

    google-chrome - 从 native 主机向浏览器扩展发送消息时获取 "Error when communicating with the native messaging host."(Windows)

    树莓派上的python mqtt脚本发送和接收消息