Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Failed to launch the browser process #69

Closed
AgniaStaravoitava opened this issue Mar 15, 2023 · 11 comments · Fixed by #76
Closed

[BUG] Failed to launch the browser process #69

AgniaStaravoitava opened this issue Mar 15, 2023 · 11 comments · Fixed by #76
Labels
bug Something isn't working

Comments

@AgniaStaravoitava
Copy link

AgniaStaravoitava commented Mar 15, 2023

"Failed to launch the browser process!\n/var/folders/ss/tlgf043d2_d50b22hy4r0tk40000gn/T/chromium: /var/folders/ss/tlgf043d2_d50b22hy4r0tk40000gn/T/chromium: cannot execute binary file\n\n\nTROUBLESHOOTING: https://pptr.dev/troubleshooting\n"

Version
"@sparticuz/chromium": "^109.0.6",
"puppeteer": "^19.7.5",
"puppeteer-core": "^19.7.5",

import chromium from '@sparticuz/chromium';
import log from 'lambda-log';
import puppeteer, { Browser, Page } from 'puppeteer-core';

export class WebSiteParserBase {
  protected pageTimeout: number;

  constructor(pageTimeout: number | null = null) {
    this.pageTimeout = pageTimeout ?? 180000;
  }

  protected async launchBrowser(headless?: boolean): Promise<Browser> {
    try {
      return await puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath(),
        headless: headless ?? chromium.headless,
        ignoreHTTPSErrors: true,
      });
    } catch (error) {
      error.reason = 'Unable to start browser';
      log.error(error);
    }
  }

  protected async goToPage(sourceUrl: string, browser: Browser): Promise<Page> {
    const page = await browser.newPage();
    await page.goto(sourceUrl, {
      timeout: this.pageTimeout,
      waitUntil: ['load', 'networkidle0', 'networkidle2'],
    });

    return page;
  }
}
@AgniaStaravoitava AgniaStaravoitava added the bug Something isn't working label Mar 15, 2023
@janvennemann
Copy link

Just ran into this as well while trying to get my project running locally with serverless-offline on my M1 Macbook. Are you trying to get it running on an ARM environment by any chance? According to #19 that's not support by this package yet.

@Myztiq
Copy link

Myztiq commented Mar 15, 2023

Probably related, but I've been trying to get around this via docker #70 and setting the --platform linux/x86_64

The only alternative that has been successful for me is to use the locally installed chromium path. In this case I am using playwright:

const executablePath = process.env.ENV === 'local'
      ? playwright.chromium.executablePath()
      : await chromium.executablePath();

@Myztiq
Copy link

Myztiq commented Mar 15, 2023

This issue is maybe a copy of #42 as well so you can likely close this out and comment over there instead with ideas.

@milindsingh
Copy link

Hi @AgniaStaravoitava I faced similar issues, but it was mostly due to version incompatibility. I have documented my ways to debug. Hope it helps!
https://adapttive.com/blog/serverless-scraping#how-to-debug

@alexcroox
Copy link

So this lib is a no-go for local testing if you have an M1/2 Mac?

@Sparticuz
Copy link
Owner

@alexcroox You can just use local chrome for testing.

set process.env.IS_LOCAL = something, and try something like this:

await puppeteer.launch({
  args: process.env.IS_LOCAL ? undefined : chromium.args,
  defaultViewport: chromium.defaultViewport,
  executablePath: process.env.IS_LOCAL ? '/path/to/Chromium' : await chromium.executablePath(),
  headless: process.env.IS_LOCAL ? false : chromium.headless,
});

@hasan-wajahat
Copy link

Hey @Sparticuz shouldn't it work locally for mac? I mean your previous package worked and so does puppeteer. I don't want to use my local Chrome as it reduces my confidence in my local env testing.
Is there a chance this is fixable?

@wickedst
Copy link

Workaround on mac in case anyone is still stuck

brew install chromium --no-quarantine

// index.js
await puppeteer.launch(
  executablePath: process.env.IS_LOCAL ? '/opt/homebrew/bin/chromium' : await chromium.executablePath(),
  // ...
});

IS_LOCAL=true node index.mjs

@conrad-scherb
Copy link

Here's a workaround I found if using with AWS SAM with M1 Macs:

@ccmetz
Copy link

ccmetz commented Sep 27, 2023

@conrad-scherb Thank you! That worked perfectly for me.

@choijun
Copy link

choijun commented Nov 9, 2023

Thank you so much @wickedst , you saved my life 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet