chrome-aws-lambda
chrome-aws-lambda copied to clipboard
Can't run Puppeteer in AWS Lambda.
I got this error when I run my scripts that use Puppeteer in Node.js.
{
"errorType": "Error",
"errorMessage": "Failed to launch the browser process!\n/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory\n\n\nTROUBLESHOOTING: https://pptr.dev/troubleshooting\n",
"trace": [
"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:259:24)",
" at Interface.emit (node:events:525:35)",
" at Interface.close (node:internal/readline/interface:533:10)",
" at Socket.onend (node:internal/readline/interface:259:10)",
" at Socket.emit (node:events:525:35)",
" at endReadableNT (node:internal/streams/readable:1359:12)",
" at process.processTicksAndRejections (node:internal/process/task_queues:82:21)"
]
}
Here is my script.
const Chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())
const browser = await puppeteer.launch({
args: Chromium.args,
defaultViewport: Chromium.defaultViewport,
executablePath: await Chromium.executablePath,
headless: Chromium.headless,
ignoreHTTPSErrors: true,
})
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36')
How can I solve this problem?
@dev1ninja I am also facing the same issue. Any solution you found or still the same issue
@pandeysoni I am still facing the same issue. It seems to be impossible to pass Cloudflare using chromium. Just have to use Real Chrome Browser. For this, the solution is to use Docker to install Google Chrome on AWS Lambda environment. But I don't know how to do it. Please let me know once you have solution. I am also trying to find good solution now.
I am having the same issue
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
Looks like there may be an issue in the examples in the readme, I'm guessing it should be
await Chromium.executablePath()
Looks like there may be an issue in the examples in the readme, I'm guessing it should be
await Chromium.executablePath()
Heyy, it seems that is not it :( node is throwing "executablePath is not a function"
What worked for me was downgrading my lambda to Node14.x and use this lambda layer: https://github.com/shelfio/chrome-aws-lambda-layer
hope it helps!
I switched to this and so far it's running (Node 18) on Lambda without any issue.
chrome-aws-lambda is not working on node 16 and node 18, it is an existing issue. "@sparticuz/chromium": "^109.0.5", "puppeteer-core": "^19.4.0" combination in working for me on node 18
I finally managed to make it worked and described the solution here, hope it's helpful: https://konarskis.substack.com/p/puppeteer-aws-lambda
The key was to match the versions of puppeteer and chromium, and download the chromium binary at runtime as opposed to trying to put it inside the Lambda itself. This way, we don't need any layers, external dependencies, or other configuration changes.
chrome-aws-lambda is not working on node 16 and node 18, it is an existing issue. "@sparticuz/chromium": "^109.0.5", "puppeteer-core": "^19.4.0" combination in working for me on node 18
This works for me as well on node 18
I finally managed to make it worked and described the solution here, hope it's helpful: https://konarskis.substack.com/p/puppeteer-aws-lambda
The key was to match the versions of puppeteer and chromium, and download the chromium binary at runtime as opposed to trying to put it inside the Lambda itself. This way, we don't need any layers, external dependencies, or other configuration changes.
Thanks for taking the time to write this up @konarskis, was very helpful!