Sparticuz / chromium

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

[BUG] Failed to launch the browser process! /tmp/chromium: /tmp/chromium: cannot execute binary file #235

Closed alexey2baranov closed 4 months ago

alexey2baranov commented 4 months ago

Environment

Expected Behavior

Run chrome, load html page and store as PDF

Current Behavior

Get an error "Failed to launch the browser process! /tmp/chromium: /tmp/chromium: cannot execute binary file TROUBLESHOOTING: https://pptr.dev/troubleshooting" when running 'puppeteer.launch()'

Steps to Reproduce

const chromium = require('chromium');
import { dirname } from 'path';
import { readdirSync } from 'fs';

exports.handler = async (event, context, callback) => {
  let result = null;
  let browser = null;

  try {
      // log tmp folder content to be sure that chromium was correctly extracted

      const executablePath = await chromium.executablePath();
      const executableDir = dirname(executablePath);

      console.info({
        executablePath,
        executableDir,
        executableDirContent: readdirSync(executableDir),
      });

    // console output: 
    // {"executablePath":"/tmp/chromium","executableDir":"/tmp","executableDirContent":["al2","chromium","fonts","libEGL.so","libGLESv2.so","libvk_swiftshader.so","libvulkan.so.1","vk_swiftshader_icd.json"]}

    browser = await puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: executablePath,
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    });
  } catch (error) {
    return callback(error);
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }

  return callback(null, result);
};

Possible Solution

I don't have a solution, I just can say what I have already done to narrow down the search.

First I've run my test locally and during the local test I was able to receive pdf file.

Also I've checked that /tmp folder contains all neccesary executables, so seems they was unarchived are present in /tmp folder (see logs above)

Also it's worth notice that we use serverless + serverless-layer plugin. But 99% it doesn't affects this issue as I performed necessary checks. First I checked that the layer contains @Sparticuz/chromium, secondly it was imported from the layer, and thirdly the files were successfully unzipped into /tmp during the first call to executablePath() (see logs above).

Sparticuz commented 4 months ago

Are you using graviton instances?

alexey2baranov commented 4 months ago

yes we do

Sparticuz commented 4 months ago

At the moment, this package only supports x86 instances, See #186