我在运行 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 的环境的详细信息:
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/