chromium: AWS lambda - Error: Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so

Environment

  • chromium Version: 126.0.0
  • puppeteer / puppeteer-core Version: 22.13.1
  • Node.js Version: 16.x and 18.x also
  • Lambda / GCF Runtime: nodejs16 and nodejs18.x

Expected Behavior

generate the pdf

Current Behavior

2024-07-18T12:46:58.968Z	2ad98127-0696-490b-8d0e-fab18650a53b	INFO	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://pptr.dev/troubleshooting

    at Interface.onClose (/var/task/node_modules/@puppeteer/browsers/lib/cjs/launch.js:310:24)
    at Interface.emit (node:events:525:35)
    at Interface.emit (node:domain:489:12)
    at Interface.close (node:readline:590:8)
    at Socket.onend (node:readline:280:10)
    at Socket.emit (node:events:525:35)
    at Socket.emit (node:domain:489:12)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Steps to Reproduce

const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");

exports.handler = async (event, context, callback) => {
  let result = null;
  let browser = null;

  try {
       chromium.setHeadlessMode = true;
       chromium.setGraphicsMode = false;

       const browser = await puppeteer.launch({
           args: [
               '--disable-setuid-sandbox',
               '--no-sandbox'
           ],
           executablePath: await chromium.executablePath(),
           headless: chromium.headless
       });

       let page = await browser.newPage();
       let html = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
       await page.setContent(html);
       let name = 'example.pdf'
       let x = await page.pdf({ path: name, format: 'Letter' });
       await browser.close();    
  } catch (error) {
    return callback(error);
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }

  return callback(null, result);
};

Possible Solution

provide the missing libnss3.so shared object file for the browser executable

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I was able to clear this error by upgrading chromium, puppeteer, and node runtime.

  @sparticuz/chromium: ^132.0.0
  puppeteer-core: ^24.1.1
  runtime: nodejs20.x

@hpardess worked for me too!

So all those libnss, libnspr4.so errors are actually because Linux/whatever which runs lambda missing these libraries but chrome kind of expects them.

I was able to run @Sparticuz/chromium 131.0.1 and puppeteer 24.0.1 on latest AWS Lambda node 22 runtime

Essentially, I copied 3 libraries from Ubuntu Jammy .deb packages libnspr4 libnss3 libsqlite3-0

And added them as separate layer. Since layers got unpacked into /opt, and LD_LIBRARY_PATH already contains /opt/lib adding to layer lib with all these *.so files solves this issue.

P.S. I am not sure why code in setupLambdaEnvironment does not work - I use serverless framework P.P.S. Please not libsqlite is also needed and missing

I was able to clear this error by upgrading chromium, puppeteer, and node runtime.

  @sparticuz/chromium: ^132.0.0
  puppeteer-core: ^24.1.1
  runtime: nodejs20.x

^ Can Confirm. Just upgraded our lambda from nodejs 18.x to nodejs22.x runtime as AWS is retiring older runtimes. And created new lambda layer versions with updated above versions. (we use both arm64 and x86_64 runtimes)

@Sparticuz I’m getting the error about libnss3.so missing. Can you advise on how to get this working? We’re using a Lambda layer, and the Lambda func is x86_64, Node.js 22. See process.env below.

ENV vars
  AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
  AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs22.x',
  AWS_DEFAULT_REGION: 'us-east-1',
  AWS_LAMBDA_LOG_STREAM_NAME: '2025/01/21/[$LATEST]cc2908bb83f24eda84dc9282c61a7414',
  AWS_REGION: 'us-east-1',
  PWD: '/var/task',
  _HANDLER: 'index.handler',
  TZ: ':UTC',
  LAMBDA_TASK_ROOT: '/var/task',
  LANG: 'en_US.UTF-8',
  AWS_SECRET_ACCESS_KEY: 'xxx',
  AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/_playwright',
  AWS_LAMBDA_RUNTIME_API: '169.254.100.1:9001',
  AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1024',
  LAMBDA_RUNTIME_DIR: '/var/runtime',
  _AWS_XRAY_DAEMON_ADDRESS: '169.254.100.1',
  AWS_XRAY_DAEMON_ADDRESS: '169.254.100.1:2000',
  SHLVL: '0',
  AWS_ACCESS_KEY_ID: 'xxx',
  LD_LIBRARY_PATH: '/tmp/aws/lib:/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib',
  NODE_PATH: '/opt/nodejs/node22/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task',
  AWS_LAMBDA_FUNCTION_NAME: '_playwright',
  PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin',
  AWS_LAMBDA_INITIALIZATION_TYPE: 'on-demand',
  AWS_SESSION_TOKEN: 'xxx',
  AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR',
  _AWS_XRAY_DAEMON_PORT: '2000',
  FONTCONFIG_PATH: '/tmp/aws',