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.


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store