Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run Puppeteer in AWS Lambda. #294

Open
dev1ninja opened this issue Jun 1, 2023 · 10 comments
Open

Can't run Puppeteer in AWS Lambda. #294

dev1ninja opened this issue Jun 1, 2023 · 10 comments
Labels
bug Something isn't working

Comments

@dev1ninja
Copy link

dev1ninja commented Jun 1, 2023

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 dev1ninja added the bug Something isn't working label Jun 1, 2023
@pandeysoni
Copy link

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

@dev1ninja
Copy link
Author

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

@sunil-buddala
Copy link

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

@kro12
Copy link

kro12 commented Jun 21, 2023

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

await Chromium.executablePath()

@kcalixto
Copy link

kcalixto commented Jun 25, 2023

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!

@kro12
Copy link

kro12 commented Jun 26, 2023

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

@Shamanthkolegodu
Copy link

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

@konarskis
Copy link

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.

@Jxmedia
Copy link

Jxmedia commented Jan 30, 2024

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

@alex-andrey
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants