Skip to content

Can't run Puppeteer in AWS Lambda. #294

@dev1ninja

Description

@dev1ninja

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions