Sparticuz / chromium

Chromium (x86-64) for Serverless Platforms
MIT License
899 stars 61 forks source link

[BUG] spawn Unknown system error -8 #63

Closed jasonlew closed 1 year ago

jasonlew commented 1 year ago

Environment

Expected Behavior

I tried to run the code here.

Current Behavior

Error: spawn Unknown system error -8
    at ChildProcess.spawn (node:internal/child_process:413:11)
    at Module.spawn (node:child_process:757:9)
    at BrowserRunner.start (file:///app/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.js:91:34)
    at ChromeLauncher.launch (file:///app/node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js:68:16)

Steps to Reproduce

See above.

jasonlew commented 1 year ago

I downgraded to Node 16.19.1, but now I'm getting:

Error: Failed to launch the browser process!
/var/folders/_k/pn98_hgn4cx_y2hw173_g1xw0000gn/T/chromium: /var/folders/_k/pn98_hgn4cx_y2hw173_g1xw0000gn/T/chromium: cannot execute binary file
Sparticuz commented 1 year ago

does the file download to /tmp/chromium-pack? What architecture is your cpu, this will only work on x86-64 processors.

jasonlew commented 1 year ago

I'm running a 2.4 GHz 8-Core Intel Core i9 on Mac. Is it because it won't work on Mac?

Also, is it supposed to work on Node 18 or only up to Node 16?

Sparticuz commented 1 year ago

It should support 16 and 18, not sure about 14 since it's EOL in a few weeks. It's compiled specifically for aws lambda, but I don't see any reason why it shouldn't work on the Mac though.

Kal-Toh commented 1 year ago

I'm having a similar error. I'm running this on Netlify dev on a m1 Mac to be pushed as a server less function on Netlify.

const puppeteer = require('puppeteer-core');
const chromium = require('@sparticuz/chromium');
exports.handler = async function (event, context) {
  if (event.httpMethod === 'OPTIONS') {
    return {
      statusCode: 200,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'Content-Type',
        'Access-Control-Allow-Methods': 'POST',
      },
      body: '',
    };
  }

  const browser = await puppeteer.launch({
    args: chromium.args,
    executablePath: await chromium.executablePath(),
    headless: chromium.headless,
  });

Returns me the error of: Error - spawn Unknown system error -8


Object.spawn (node:child_process:757:9)
BrowserRunner.start (/Users/xyz/1.5/Server/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:120:34)
ChromeLauncher.launch (/Users/xyz/1.5/Server/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:97:16)
async exports.handler (/Users/xyz/1.5/Server/functions/quote.js:20:19)
rfoel commented 1 year ago

Getting this error on mac M1 too. When I deploy to a lambda it works using this executablePath:

      executablePath: await chromium.executablePath(
        process.env.AWS_EXECUTION_ENV
          ? '/opt/nodejs/node_modules/@sparticuz/chromium/bin'
          : undefined,
      ),
Kal-Toh commented 1 year ago

Yeah, the issue for me was that it wasn't compatible with my systems architecture, thus wouldn't work on a local environment. It functions as expected when deployed.

Best thing to do is code>deploy>test>code>deploy>test etc.

rfoel commented 1 year ago

@Kal-Toh I've managed to make it work... with playwright. I've installed playwright-core as a dependency and playwright as a devDependency and now it knows how to spawn the browser. I've tried the same solution with puppeteer but I couldn't make it work.

const browser = await playwright.chromium.launch({
      args: chromium.args,
      executablePath: process.env.AWS_EXECUTION_ENV
        ? await chromium.executablePath(
            '/opt/nodejs/node_modules/@sparticuz/chromium/bin',
          )
        : playwright.chromium.executablePath(),
      headless: true
    })
bhaktatejas922 commented 1 year ago

not working for me either on m1 mac

Sparticuz commented 1 year ago
executablePath: process.env.AWS_EXECUTION_ENV
        ? await chromium.executablePath(
            '/opt/nodejs/node_modules/@sparticuz/chromium/bin',
          )
        : playwright.chromium.executablePath(),

Yes, this is the correct way to handle arm at this point. You are saying if I'm running in AWS, use this package, otherwise, use playwright's version of chromium. I'm going to document this and close the multiple issues about running on ARM and running Headfully. Thanks for the insight.

felipeclopes commented 1 year ago

does the file download to /tmp/chromium-pack? What architecture is your cpu, this will only work on x86-64 processors.

When running serverless invoke local --function <name> the standard code doesn't work on x86-64 Mac OS.

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

Do I need to use playwright to execute locally even on x86 architectures?

PS.: My setup is running fine when deployed (Layer -> AWS Lambda)

bhaktatejas922 commented 1 year ago

on M1 you can do a arch -x86_64 zsh

in your terminal prior to running and it should work. You'll need to have the x86 packages installed prior to. You can do it by running this for example

npm install --arch=x86 --save puppeteer-core@18.0.5 npm install --arch=x86 --save @sparticuz/chromium@106

andredezzy commented 10 months ago

Any news how about to execute locally even on M1/M2?

andredezzy commented 10 months ago
import chromium from '@sparticuz/chromium-min';
import { executablePath } from 'puppeteer';
import * as puppeteer from 'puppeteer-core';

 browser = await puppeteer.launch(
      process.env.NODE_ENV === 'production'
        ? {
            args: chromium.args,
            defaultViewport: chromium.defaultViewport,
            executablePath: await chromium.executablePath(
              'https://drive.google.com/uc?id=1Sw60gty75maoAr2fsIcu-CDJZ5O8RHrm&export=download',
            ),
            headless: chromium.headless,
            ignoreHTTPSErrors: true,
          }
        : {
            headless: false,
            executablePath: executablePath(),
          },
    );

For local development I did this and bow it's working.

charleswklau commented 6 months ago

@andredezzy

I also use the same approach. It works for me as well.

But have you experienced the PDF output difference? because sometimes I got an extra page, or some inconsistent styles in the remote/production side. It looks perfect in the local development.

asadimohammad commented 6 months ago

This happened for me because I was on the new macOS "Apple Silicon" in the terminal Apple will not prompt you to install Rosetta which is required for certain apps to run. Simply running softwareupdate --install-rosetta solved the issue for me.

More information about Rosetta here https://support.apple.com/en-gb/HT211861

sedukhsergey commented 6 months ago

For me it works with next solution

  1. install Chromium and make a fix because without it the error can happen when you try to launch Cromium. https://dev.to/pixelrena/installing-chromium-on-mac-apple-m2-pro-tutorial-4i4i

  2. Use next code for launch pupeeter locally https://github.com/puppeteer/puppeteer/issues/6634#issuecomment-755430921

On my side it looks like.

import chromium from '@sparticuz/chromium';
import puppeteerCore from 'puppeteer-core';
import puppeteer from 'puppeteer';
...
      if (process.env.STAGE === 'local') {
        browser = await puppeteer.launch({
          executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
          args: ['--no-sandbox', '--disable-setuid-sandbox'],
          headless: false,
        });
        console.log('browser', browser);
      }

      if (process.env.STAGE !== 'local') {
        browser = await puppeteerCore.launch({
          args: chromium.args,
          defaultViewport: chromium.defaultViewport,
          executablePath: await chromium.executablePath(),
          headless: chromium.headless,
          ignoreHTTPSErrors: true,
        });
      }
    ...

Mac M1. Node.js v18.18.2

And from the package.json "@sparticuz/chromium": "110.0.0", "puppeteer": "19.6.3", "puppeteer-core": "19.6.3",