chromium: AWS lambda - Error: Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so
Environment
chromiumVersion: 126.0.0puppeteer/puppeteer-coreVersion: 22.13.1- Node.js Version: 16.x and 18.x also
- Lambda / GCF Runtime:
nodejs16andnodejs18.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)
I was able to clear this error by upgrading chromium, puppeteer, and node runtime.
@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
^ 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.envbelow.