chromium icon indicating copy to clipboard operation
chromium copied to clipboard

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

Open kisglaci opened this issue 1 year ago • 7 comments

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

kisglaci avatar Jul 18 '24 12:07 kisglaci

similar to https://github.com/Sparticuz/chromium/issues/254 https://github.com/alixaxel/chrome-aws-lambda/issues/164#issuecomment-2236440828

kisglaci avatar Jul 22 '24 08:07 kisglaci

@kisglaci any update? I've been struggling with the same issue.

mbutan avatar Aug 07 '24 15:08 mbutan

Missing library means that the al2 or al2023 file is not being extracted. (Or less common, the runtimes have been updated and the included libraries are out of date)

Sparticuz avatar Aug 07 '24 15:08 Sparticuz

Having the same issue, but running with node 20, chromium v123.0.1:

image

joaocarlospf avatar Aug 27 '24 10:08 joaocarlospf

any update ? still struggling with that problems

sylvio-jerry avatar Aug 31 '24 07:08 sylvio-jerry

waiting for an update as well

Update: downgrade to

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "22.5.0",

and I missed the () in the line:

 executablePath: await chromium.executablePath(),

Now everything works for me

Guy7B avatar Sep 08 '24 10:09 Guy7B

waiting for an update as well

Update: downgrade to

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "22.5.0",

and I missed the () in the line:

 executablePath: await chromium.executablePath(),

Now everything works for me

working locally, but not in AWS Lambda / GCF Runtime: nodejs18.x

kisglaci avatar Sep 10 '24 14:09 kisglaci

anyone solve this?

cantonalex avatar Dec 12 '24 06:12 cantonalex

I'm going to close this issue because the reason for this error is known. I'm not able to solve these unless the runtime environment is detectable. See https://github.com/Sparticuz/chromium/issues/321#issuecomment-2500413723 for more information. If you are experiencing this error. I'll need a dump of process.env as well as other information about the environment that you are trying to run it in.

Sparticuz avatar Dec 16 '24 14:12 Sparticuz

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

huksley avatar Jan 15 '25 13:01 huksley

@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',

ffxsam avatar Jan 21 '25 21:01 ffxsam

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

mjtribble avatar Feb 02 '25 02:02 mjtribble

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)

skulkarni-fs avatar Feb 21 '25 22:02 skulkarni-fs

If anyone has a known fix/workaround for Playwright, I'd appreciate it!

ffxsam avatar Feb 22 '25 00:02 ffxsam

If anyone has a known fix/workaround for Playwright, I'd appreciate it!

I'm in the same situation.. :S

Have you found a solution ?

cecicifu avatar Mar 08 '25 14:03 cecicifu

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

I was able to resolve the issue with upgrading the libraries and runtime...

hpardess avatar May 09 '25 16:05 hpardess

@hpardess worked for me too!

lucasferreiraestevam avatar Jun 05 '25 17:06 lucasferreiraestevam

I am getting the same error on the latest version of this lib and puppeteer. Can anybody please help? Here are my dep:

"@sparticuz/chromium": "^138.0.2", "puppeteer-core": "^24.1.1"

Edit: I am trying to run it on Google Cloud Function with Node 22.x runtime

krishna-sharma-dev avatar Aug 19 '25 14:08 krishna-sharma-dev

I ran into this problem myself using AWS Lambda.

Understanding that the problem in my case is that the environment is not correctly detected, therefore not setup correctly, I built the missing dependencies into my lambda layer directly.

Gist for anyone interested: https://gist.github.com/brendanerofeev/eff5b60c8ab343245ec6060e3b5e0ced

brendanerofeev avatar Aug 22 '25 06:08 brendanerofeev