Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppeteer not working on vps but running locally

I wrote a little puppeteer program that let me log into twitter and check a few things. Locally on mac OS Catalina, it is working but on VPS ubuntu 18.04 lts not working. And shows me a log at the start:

/root/retwiter/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

I have 2 running configs for browser: local:

{
    headless: false,
    defaultViewport: null,
    args: [
        '--window-size=1920,1080'
    ]
}

vps:

{
    headless: true,
    defaultViewport: null,
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox'
    ]
}
like image 723
programmer Avatar asked Oct 14 '20 21:10

programmer


People also ask

How much RAM does puppeteer need?

Memory requirements Actors using Puppeteer: at least 1GB of memory. Large and complex sites like Google Maps: at least 4GB for optimal speed and concurrency.

Is puppeteer headless by default?

Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

What is headless mode in puppeteer?

Advertisements. By default, Puppeteer executes the test in headless Chromium. This means if we are running a test using Puppeteer, then we won't be able to view the execution in the browser. To enable execution in the headed mode, we have to add the parameter: headless:false in the code.

Does puppeteer require Chrome installed?

Puppeteer is a Node. js library developed by Google that lets you control headless Chrome through the DevTools Protocol. It is a tool for automating testing in your application using headless Chrome or Chromebit devices, without requiring any browser extensions like Selenium Webdriver or PhantomJS.


3 Answers

i think you are missing the library libnss3 , try to install it using

sudo apt-get install libnss3-dev

and if that's not enough install all the deps for puppeteer

sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
like image 181
Chamsddine Bouzaine Avatar answered Jan 01 '23 06:01

Chamsddine Bouzaine


You can add AWS Elastic Beanstalk configuration files (.ebextensions) to your web application's source code to configure your environment and customize the AWS resources that it contains.

In our case, if we don't enable EPEL and if we continue installing Chromium as part of npm install, Puppeteer cannot launch Chromium due to unavailability of libatk-1.0.so.0.

  • Source @ Running Puppeteer on AWS EC2 instance running Amazon-Linux

Hotfix

Add the following to your app root:

  1. Create a .npmrc file.
  2. Add the following to your .npmrc file:
unsafe-perm=true

The .npmrc file defines how npm should behave when running commands. Setting unsafe-perm to true suppress the UID/GID switching when running package scripts. Set the unsafe-perm flag to run scripts with root privileges.

  • Source @ unsafe-perm
  1. Create a .ebextensions folder.
  2. Inside .ebextensions folder, create a 01_enableEPEL.config file and add the following.
commands:
  01_enableEPEL:
    command: sudo amazon-linux-extras install epel -y
  1. Inside .ebextensions folder, create a 02_installEPELPackages.config file and add the following
packages:
  yum:
    chromium: []

You can view the same guide on my GitHub @ https://github.com/amarinediary/Marionette

like image 23
amarinediary Avatar answered Jan 01 '23 04:01

amarinediary


If on CentOS, you can use this command with the correct dependencies:

sudo yum install -y alsa-lib.x86_64 atk.x86_64 cups-libs.x86_64 gtk3.x86_64 ipa-gothic-fonts libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXrandr.x86_64 libXScrnSaver.x86_64 libXtst.x86_64 pango.x86_64 xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-fonts-cyrillic xorg-x11-fonts-misc xorg-x11-fonts-Type1 xorg-x11-utils

sudo yum update nss -y
like image 35
Air One Avatar answered Jan 01 '23 05:01

Air One