Sparticuz / chromium

Chromium (x86-64) for Serverless Platforms
MIT License
846 stars 57 forks source link

[BUG] Failed to launch the browser process! #237

Closed robbymarston closed 3 months ago

robbymarston commented 3 months ago

Environment

Expected Behavior

The browser process should start up normally.

Current Behavior

The browser process does not start; instead, throwing the following error:

Error: Failed to launch the browser process!

Steps to Reproduce

  1. Set up a Lambda function with the following code:
import puppeteer from '/opt/node_modules/puppeteer-core/lib/cjs/puppeteer/puppeteer-core.js';
import chromium from '/opt/node_modules/@sparticuz/chromium/build/index.js';

chromium.setHeadlessMode = true;

(async () => {
  try {
    const browser = await puppeteer
      .launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath(),
        headless: chromium.headless,
      });
    } catch (error) {
      console.error(error);
    }
})();
  1. Set up an accompanying layer that includes both puppeteer-core and chromium.
  2. Trigger the function and observe the CloudWatch logs.

Possible Solution

Sparticuz commented 3 months ago

We don't work in graviton instances, please verify that you are runing in x86

robbymarston commented 3 months ago

Thank you for the quick response (and fantastic work) @Sparticuz. I am using x86. Here's the full template (with ARNs redacted):

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application Model template describing your function.
Resources:
  HelloWorld:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Description: ''
      MemorySize: 512
      Timeout: 3
      Handler: index.handler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      EphemeralStorage:
        Size: 512
      EventInvokeConfig:
        MaximumEventAgeInSeconds: 21600
        MaximumRetryAttempts: 2
      FunctionUrlConfig:
        AuthType: NONE
        InvokeMode: BUFFERED
      Layers:
        - <ARN>
      PackageType: Zip
      Policies:
        - Statement:
            - Effect: Allow
              Action:
                - logs:CreateLogGroup
              Resource: <ARN>
            - Effect: Allow
              Action:
                - logs:CreateLogStream
                - logs:PutLogEvents
              Resource:
                - >-
                  <ARN>
      SnapStart:
        ApplyOn: None
      RuntimeManagementConfig:
        UpdateRuntimeOn: Auto
Sparticuz commented 3 months ago

512 memory size is too small, try putting it over 1500 megs

robbymarston commented 3 months ago

Using the chromium-min package, as well as upping both the max. memory and timeout values seemed to have done the trick. Thank you!