Use Puppeteer on node.js in Armbian (for web automation)


Recommended Posts

How to install Puppeteer on node.js on Armbian.  Tested on OrangePi Zero Plus running Ubuntu Xenial or Bionic.

 Should work on other boards and other builds.

 

How to install the latest version of node.js. (at the time of writing was 12.7.0).

Instructions for installing node.js on Debian and Ubuntu can be found at:
https://github.com/nodesource/distributions/blob/master/README.md#deb
 
The instructions at the time of writing were:
 

# Using Ubuntu

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root

curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

 

Both of these methods work on Ubuntu.

 

If you then try to install Puppeteer using "npm i puppeteer" you will discover that the version of Chrome that it installs locally is for the wrong CPU architecture.

The solution to the problem is to install and use puppeteer-core instead of puppeteer.
When using puppeteer core, you must define the path to Chrome or Chromium in the puppeteer script (see the test example below).

 

First install a recent version of Chromium Browser.  This will be used in headerless mode.

apt-get install chromium-browser

When the chromium-browser install is complete

Create a folder for your Puppeteer project
 

Let's assume that your folder is in /mnt/data/nodejs-scripts/screenshot (mine was on a mounted ntfs drive).

cd /mnt/data/nodejs-scripts/screenshot

npm init -y

npm i puppeteer-core --save

Now create a node.js test script

Lets say that you call it screenshot.js

Using your favorite editor insert the following lines into the file.

const puppeteer = require('puppeteer-core');

(async ()=>{
    const browser = await puppeteer.launch({
        executablePath: '/usr/bin/chromium-browser',
        args: ['--no-sandbox'],
        headless: true
    });

const page = await browser.newPage();

await page.goto('https://duckduckgo.com/');

await page.screenshot({path: 'screenshot.png'});

await browser.close();

})();

 

Make the script executable.

chmod +x screenshot.js

You can now run the script

cd /mnt/data/nodejs-scripts/screenshot

nodejs screenshot.js

If it has worked, you will find a screenshot of the DuckDuckGo page in your project folder.

 


 

 

 

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...