[BUG] Failed to launch the browser process: error while loading shared libraries: libnss3.so: cannot open shared object file

See original GitHub issue

Environment

  • chrome-aws-lambda Version: 3.0.4
  • puppeteer / puppeteer-core Version: 3.0.4
  • OS: Mac
  • Node.js Version: 12.x
  • Lambda / GCF Runtime: nodejs12.x

Expected Behavior

Chrome should have load.

Current Behavior

Error: Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md at onClose (/var/task/node_modules/puppeteer-core/lib/Launcher.js:547:20) at Interface.<anonymous> (/var/task/node_modules/puppeteer-core/lib/Launcher.js:537:65) at Interface.emit (events.js:327:22) at Interface.EventEmitter.emit (domain.js:483:12) at Interface.close (readline.js:416:8) at Socket.onend (readline.js:194:10) at Socket.emit (events.js:327:22) at Socket.EventEmitter.emit (domain.js:483:12) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

Steps to Reproduce

const chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');

  async convertToPdf(request) {
    try {
      console.log('Starting puppeteer browser.');

      const browser = await chromium.puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath,
        headless: true,
        ignoreHTTPSErrors: true
      });

      console.log('Puppeteer launched: ' + !!browser);


      if (request.sections.length > 75) {
        throw new Error('Only 75 report sections are allowed');
      }

      let pdfs = await Promise.all(_.map(request.sections, async (section, $index) => {
        if (section.s3Pdf) {
          let s3Response = await s3.getObject({
            Bucket: section.s3Pdf.bucket,
            Key: section.s3Pdf.key
          }).promise();

          console.log(`PDF ${$index} retrieved successfully`);
          return s3Response.Body;
        }
        const page = await browser.newPage();

        page.setViewport(request.viewPort || {
          width: 1024,
          height: 600
        });

        section.options = section.options || {};

        console.log(`Loading section ${$index}...`);
        await page.setContent(this.fromBase64(section.html), {waitUntil: ['networkidle0']});
        console.log(`Section ${$index} Load complete. Converting html to pdf using puppeteer. Options: ${JSON.stringify(section.options)}`);

        let body = await page.pdf(_.assign({format: 'letter'}, section.options));

        console.log(`PDF ${$index} created successfully`);
        page.close();
        return body;
      }));

Previously my code was running properly on nodejs8.10 supported AWS Lambda function but after forcefully upgrade to nodejs12.x, my code starts to throw this error. I tried upgrading chrome-aws-lambda and puppeteer-core version to 2.1.1 and even the latest 5.3.1 but no luck on resolving the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

104reactions
damisparkscommented, Jan 5, 2021

Here is how I fixed mine.

  • First, I ran an update.
sudo apt-get update
  • Move to the chromium directory.
cd /project_folder/node_modules/puppeteer/.local-chromium/[linux-579032]/[chrome-linux]

but replace the bracketed directories with the directories available in your node_modules folder. There you should find the local installation of chrome and from there you ran the next command.

  • Next, run this
ldd chrome | grep not

on a Linux machine to check which dependencies are missing. Read more here Chrome headless doesn’t launch on UNIX

  • Run this to install the missing libraries or packages.
sudo apt-get install libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0
sudo apt-get install -y libgbm-dev
  • Run this again to check if the missing packages are installed ldd chrome | grep not this time nothing is shown on the terminal, so you should be good.
  • In your JS code, add this
const browser = await puppeteer.launch({
    headless: true,
    args: ['--no-sandbox'] });

That is it. You are good to go. Hopefully, this helps someone. 😄

26reactions
Sandstedtcommented, Dec 2, 2020

I get the same error, but not related to AWS, but Linux on a Windows 10 machine using WSL 2 (Ubuntu 20.04.1 LTS) and Puppetter: 5.5.0: ChromeHeadless stderr: /home/sandstedt/_open-source/mojs/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

Solved it by installing all missing dependencies listed here: Puppeteer Troubleshooting

Read more comments on GitHub >

github_iconTop Results From Across the Web

error while loading shared libraries: libnss3.so: cannot open ...
The most common cause is a bug in Node.js v14.0.0 which broke extract-zip, the module Puppeteer uses to extract browser downloads into the...
Read more >
13425 - error while loading shared libraries: libnss3.so.1d
/tmp/opt/google/chrome/chrome: error while loading shared libraries: libnss3.so.1d: cannot open shared object file: No such file or directory
Read more >
libnss3.so: cannot open shared object file - You.com | The AI ...
[BUG] Failed to launch the browser process: error while loading shared libraries: libnss3.so: cannot open shared object file. Open side panel.
Read more >
[BUG] Failed to launch the browser process - Bountysource
[BUG] Failed to launch the browser process: error while loading shared libraries: libnss3.so: cannot open shared object file.
Read more >
Why is MATLAB unable to run the MATLABWindow ...
bin/glnxa64/MATLABWindow: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory. Then you should:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found