Ubuntu 22.04 install Puppeteer

Install npm, Puppeteer and dependencies:

apt update -y && apt upgrade -y
apt install -y npm
apt install -y 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 libgbm1
npm install -g n
n lts
hash -r
npm install puppeteer

Install Chrome without snap:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb

Make a test file test.js:

const puppeteer = require('puppeteer');
const fs = require('fs');

async function run () {
  const browser = await puppeteer.launch({
    executablePath: '/usr/bin/google-chrome-stable',
    args: ['--no-sandbox'],
    defaultViewport: {width: 1920, height: 1080}
  });
  const page = await browser.newPage();
  await page.goto('https://www.google.com');
  await sleep(3000);

  await page.screenshot({path: 'screenshot.png'});
  const html = await page.content();
  fs.writeFileSync('source.htm', html);

  browser.close();
}
run();

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
} 

Test it:

node test.js

1 comment

  1. I switched from sudo to root because the terminal commands did not otherwise work, and everything seemed to go okay. However, when I got to the ‘make a test.js file’ instructions, the code did not work in the terminal, and so I assume that the instructions mean to make a JavaScript file in the same way that one would create an external script.js file to link to an HTML page, but name it ‘test.js’. However, what directory would I save it in? Would I change to that directory in the terminal and then enter the command ‘node test.js’? What should I expect? There’s a lot unsaid here. I want to use puppeteer to lock down a version of Chrome/Chromium that can generate .pdf pages from @page sections of an HTML page. I’m concerned that Sergey Brin might play games with Chrome updates after finding that my intended legal pleadings word processor is using Chrome to generate the .pdf legal pleadings in litigation affecting Israel’s interests. Chrome/Chromium is the only browser that I have been able to use that does not add extra unwanted space to the .pdf pages. Any suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *