alixaxel / chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions
MIT License
3.17k stars 289 forks source link

[BUG] Chromium binary can't be executed #262

Closed enmanuelmag closed 2 years ago

enmanuelmag commented 2 years ago

Environment

Expected Behavior

Load chromium binary on AWS Lambda to render a html.

Current Behavior

The binary chromium can't be execute.

CleanShot 2022-02-25 at 09 44 21@2x

Steps to Reproduce

Create a AWS Lambda with docker using the image public.ecr.aws/lambda/nodejs:14-arm64 and add code to load any page from html String using the chrome-aws-lambda.

async function generatePdf(file, options, callback) {
  const executablePath = await chromium.executablePath;
  console.log('Args browser', chromium.args);
  console.log('Executable path', executablePath);
  let browser;
  try {
    browser = await chromium.puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: executablePath,
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    }); //the error throw in this line
    const page = await browser.newPage();

    if(file.content) {
      data = await inlineCss(file.content, {url:"/"});
      console.log("Compiling the template with handlebars")
      // we have compile our code with handlebars
      const template = hb.compile(data, { strict: true });
      const result = template(data);
      const html = result;

      // We set the page content as the generated html by handlebars
      await page.setContent(html, {
        waitUntil: 'networkidle0', // wait for page to load completely
      });
    } else {
      await page.goto(file.url, {
        waitUntil:[ 'load', 'networkidle0'], // wait for page to load completely
      });
    }
  } catch (error) {
    return callback(error);
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }

}
bestplay9384 commented 2 years ago

Version 10.1.X of this project works only with puppeteer 10.1.X, it won't work with newer puppeteer versions.

enmanuelmag commented 2 years ago

@bestplay9384 thanks! I will make the change now and test it.

enmanuelmag commented 2 years ago

@bestplay9384 I'm still facing the same problem, I set on package.json the version 10.1.0 for puppeteer-core (the same as this project)

CleanShot 2022-02-25 at 11 39 13@2x
marcelpanse commented 2 years ago

I'm running into the same issue. Isn't this the same problem as #241?

bestplay9384 commented 2 years ago

Are you guys using it as AWS Lambda Layer attached to the lambda? Then /opt/chromium is the correct path to executable. I'm sure it won't fit to upload whole chrome-aws-lambda dependency with your lambda code as zip. As far as i remember zip code filesize limit is still 50 MB. Also i haven't used it all with node 14.x yet, it works fine for me but on node 12, maybe it is the issue?

bestplay9384 commented 2 years ago

I think the issue is the OS image You are using @enmanuelmag, chromium binary is precompiled on Amazon Linux 2 Image, and its the only one you should use chrome-aws-lambda project with - binaries works only on this OS.

marcelpanse commented 2 years ago

@bestplay9384 The docker image he is mentioning is the same as I am using. I just checked and it already is Amazon Linux 2.

sh-4.2# cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
VARIANT_ID="202201251954-2.0.728.0"

I don't think the chromium binaries are precompiled on the arm64 version though. I'm also unable to install it.

bestplay9384 commented 2 years ago

Yes, these binaries are x86-only compatible i think.

enmanuelmag commented 2 years ago

Ohh okay thanks, I guess that you can close this issue. The problem is the Lambda Arch-arm64