chrome-aws-lambda icon indicating copy to clipboard operation
chrome-aws-lambda copied to clipboard

Can't run Puppeteer in AWS Lambda.

Open dev1ninja opened this issue 1 year ago • 11 comments

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 avatar Jun 01 '23 13:06 dev1ninja

@dev1ninja I am also facing the same issue. Any solution you found or still the same issue

pandeysoni avatar Jun 09 '23 16:06 pandeysoni

@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.

dev1ninja avatar Jun 09 '23 16:06 dev1ninja

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

sunil-buddala avatar Jun 11 '23 11:06 sunil-buddala

Looks like there may be an issue in the examples in the readme, I'm guessing it should be

await Chromium.executablePath()

kro12 avatar Jun 21 '23 16:06 kro12

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!

kcalixto avatar Jun 25 '23 16:06 kcalixto

I switched to this and so far it's running (Node 18) on Lambda without any issue.

kro12 avatar Jun 26 '23 08:06 kro12

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

Shamanthkolegodu avatar Oct 05 '23 06:10 Shamanthkolegodu

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.

konarskis avatar Jan 14 '24 13:01 konarskis

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

Jxmedia avatar Jan 30 '24 15:01 Jxmedia

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!

alex-andrey avatar May 01 '24 11:05 alex-andrey