首页 > 解决方案 > Raspberry pi 零 w 上的 Puppeteer

问题描述

我想在 Raspberry pi 零 w 上使用 puppeteer 运行节点 js 脚本,但出现此错误:

(node:5699) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 1: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: �: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 1: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: ELF: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 2: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: p#: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 3: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: p#: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 4: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: @l�: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 5: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: pX: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 6: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: pX: not found
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 7: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: Syntax error: "(" unexpected
/SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: 4: /SteamCheaper/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: ��q: not found

你能告诉我,我能用它做什么吗?

标签: node.jslinuxnpmraspberry-pipuppeteer

解决方案


Puppeteer 默认使用捆绑的 Chromium。该错误表明它无法启动它。

您应该手动安装 Chromium 并让 Puppeteer 使用该版本。假设您已将其安装在 中/usr/bin/chromium,这样的事情就可以完成:

const browser = await puppeteer.launch({
    product: "chrome", executablePath: "/usr/bin/chromium",
})

推荐阅读