Sparticuz / chromium

Chromium (x86-64) for Serverless Platforms
MIT License
923 stars 62 forks source link

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

Open kisglaci opened 1 month ago

kisglaci commented 1 month ago

Environment

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 commented 1 month ago

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

mbutan commented 1 month ago

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

Sparticuz commented 1 month ago

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)

joaocarlospf commented 1 week ago

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

image

sylvio-jerry commented 6 days ago

any update ? still struggling with that problems