Ubuntu install puppeteer

Installing puppeteer into a fresh AWS EC2 Ubuntu 18.04 and its dependencies.

sudo apt update
sudo apt upgrade
sudo apt install npm
npm i puppeteer

Now run a simple puppeteer script and you will encounter errors about missing shared libraries. A simple script below, lets name it simple.js

const puppeteer = require('puppeteer');
async function run () {
   const browser = await puppeteer.launch({
      defaultViewport: {width: 1920, height: 1080}
   });
   const page = await browser.newPage();
   await page.goto('https://www.google.com/search?q=bitcoin');
   await page.screenshot({path: 'screenshot.png'});
   browser.close();
}
run(); 
node simple.js

Now install the dependencies and rerun.

sudo apt install libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi-dev libxtst-dev libnss3 libcups2 libxss1 libxrandr2 libasound2 libatk1.0-0 libatk-bridge2.0-0 libpangocairo-1.0-0 libgtk-3-0

Simple puppeteer script to google for search results.

const puppeteer = require('puppeteer');
 const fs = require("fs");
 async function run () {
   const browser = await puppeteer.launch({
     defaultViewport: {width: 1920, height: 1080}
   });
   const page = await browser.newPage();
   await page.goto('https://www.google.com');
   await page.waitFor('input[class="gLFyf gsfi"]');
   await page.$eval('input[class="gLFyf gsfi"]', el => el.value = 'bitcoin');
   await page.$eval('input[class="gNO89b"]', el => el.click());
 await page.waitForSelector('div#result-stats');
   await page.screenshot({ path: 'screenshot.png' });
 const html = await page.content()
   fs.writeFileSync("page.html", html);
 browser.close();
 }
 run();