chromium: [BUG] No longer working in Lambda

package.json:

    "@sparticuz/chromium": "123.0.1",
    "puppeteer-core": "22.6.4"

code:

  chromium.setGraphicsMode = false;

  console.log("## Launching browser");
  const browser = await puppeteer.launch({
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    executablePath: await chromium.executablePath(),
    headless: chromium.headless,
    ignoreHTTPSErrors: true,
  });

  console.log("## Creating new page");
  const page = await browser.newPage();

  console.log("## Setting user agent");
  await page.setUserAgent("Lambda PDF");

  console.log("## Going to " + url);
  await page.goto(url, {
    waitUntil: ["domcontentloaded", "networkidle0"],
  });

It’s freezing after “Creating new page” appears in the console logs.

Lambda 18.x (tried with 20.x too) with 2GB memory Runtime version ARN: arn:aws:lambda:eu-west-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd

About this issue

  • Original URL
  • State: open
  • Created 2 months ago
  • Reactions: 2
  • Comments: 31 (3 by maintainers)

Most upvoted comments

Downgrading to:

    "@sparticuz/chromium": "122.0.0",
    "puppeteer-core": "22.5.0"

Seems to have worked. Leaving this open just to verify I didnt make a mistake selecting the wrong package versions?

Did AWS change something with lambdas and lambda layers that is biting all of us?

Yes, AWS updated some libraries that are causing issues with the libraries included in this package. I’m in contact with the team at AWS and we will be working on a solution.

I would recommend pinning the lambda execution environment while this issue gets sorted.

setting this works chromium.setGraphicsMode = true;

FWIW I was able to get it working with:

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "^21.1.1",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-stealth": "^2.11.2",

I rolled back manualy the runtime version and it worked

This works for us.

We migrated to a previous version of Runtime on lambda(Node.Js 18.*)

ARN: arn:aws:lambda:ap-south-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9

package.json for compatibility.

"@sparticuz/chromium": "^119.0.0",
"puppeteer": "^21.5.2"

I am curious about the root cause, seems it relate to SSL lib update, but why GraphicsMode can make it solved.

Removing our disabling of the graphics mode solved this for us:

- chromium.setGraphicsMode = false
+ // FIXME: re-enable in Chromium 124
+ // ref: https://github.com/Sparticuz/chromium/issues/271#issuecomment-2085784736
+ // chromium.setGraphicsMode = false

with the following versions:

    "@sparticuz/chromium": "123.0.1",
    "playwright-core": "1.43.1",

edit: actually, not sure about this, we’re still seeing some errors

We’ve worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

@ryan-concora Specify the run time management at the “provider” or “function” level in your serverless.yml file:

functions:
  hello:
    runtimeManagement:
      mode: manual
      arn: arn:aws:lambda:us-east-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9

The ARN version in the example above works for me (The offending ARN is mentioned in OP: https://github.com/Sparticuz/chromium/issues/271#issue-2271372222) Reference: https://www.serverless.com/framework/docs-providers-aws-guide-functions

We’ve worked around it by rolling back to the previous Lambda Runtime ARN.

We have also started facing same issue. We have not update package version from 3 months. While trying to figure out the issue, we found that it is not working only when html contains https URLs as we had some https URLs in img tag and link tag. With http urls, it is working fine.

We had the following package.json

 "@sparticuz/chromium": "^109.0.5",
 "puppeteer-core": "^19.4.0",

Same thing is working fine with https URLs after updating package version to (as mentioned by @fire015 )

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "22.5.0"

Make sure to leave graphics mode enabled. The option will be fixed in the next version. I’ve been traveling so I haven’t had time to update to chromium 124.