Puppeteer on Raspbian NodeJS


If we want to use Puppeteer in nodejs, we simply do a:

npm i puppeteer
# or "yarn add puppeteer"

After that humans would think that the following code would work:

const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});

await browser.close();

Well…let me tell you, it would work…but not on an ARM Processor. And were so lucky today, because Raspberry Pi contains an ARM Processor.

You would get the following error trying to run the :

Error: Failed to launch chrome!
/home/xxxx/.../node_modules/puppeteer/.local-chromium/liniux-641577/chrome-linux/chrome: Syntax error: word unexpected (expecting ") "

Solving the issue

Install Chromium by running:
sudo apt install chromium-browser chromium-codecs-ffmpeg

It usually installs Chromium in /usr/bin/ -folder. So then we change the executablePath to the below:

const browser = await puppeteer.launch({
headless: true,
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--disable-setuid-sandbox']

That’s all, running your Nodejs program will now run puppeteer successfully and should open the Chromium browser.


类别:未分组 | 阅读:107654 | 评论:0 | 标签:



taoCMS发布taoCMS 3.0.2(最后更新21年03月15日),请大家速速升级,欢迎大家试用和提出您宝贵的意见建议。