alixaxel / chrome-aws-lambda

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

[BUG] ValidationError: browserType.launch: executablePath: expected string, got object #219

Closed BrunoQuaresma closed 3 years ago

BrunoQuaresma commented 3 years ago

When I use it with playwright-core 1.8.0 and I'm getting this error:

ValidationError: browserType.launch: executablePath: expected string, got object

Code:

const chromium = require("chrome-aws-lambda");
const playwright = require("playwright-core");

const browser = await playwright.chromium.launch({
    args: chromium.args,
    executablePath: await chromium.executablePath,
    headless: chromium.headless,
  });
BrunoQuaresma commented 3 years ago

Debugging chromium.executablePath I see its value is null

const path = await chromium.executablePath;

console.dir(path);
alixaxel commented 3 years ago

Hi @BrunoQuaresma - yes, it's null because the package didn't detect it's running on a serverless environment:

https://github.com/alixaxel/chrome-aws-lambda/blob/78fdbf1b9b9a439883dc2fe747171a765b835031/source/index.ts#L179-L192

See also https://github.com/alixaxel/chrome-aws-lambda/wiki/HOWTO:-Local-Development

BrunoQuaresma commented 3 years ago

I see, srry by the dummy question and thanks for the guidance.

pthieu commented 2 years ago

@BrunoQuaresma did you end up solving this? The example in the local dev wiki is for puppeteer, but it doesn't seem like playwright has a getter function

BrunoQuaresma commented 2 years ago

I gave up on doing this myself and I started to use this service https://www.browserless.io/

jaiminka commented 1 year ago

In .env file I added AWS_LAMBDA_FUNCTION_NAME=your functionName and It works. I can able to run the test test is passing all the way same as puppeteer with almost same timing. but, headed mode is not working. Even If I set headless: false in browser launch. Not sure why?

@BrunoQuaresma did you end up solving this? The example in the local dev wiki is for puppeteer, but it doesn't seem like playwright has a getter function

jaiminka commented 1 year ago

@BrunoQuaresma I end up doing this. It does not looks good to have import inside else but, for me this one was the only solution at that time. Install "@playwright/test" as a dev dependency so, it does not download in lambda so no problem with memory and in lambda you can use headless mode only. In local development you can use headed and headless mode.

const lambdaPlaywright = require('playwright-aws-lambda');

if (headless) {
  browser = await lambdaPlaywright.launchChromium({ headless });
} else {
  const regularPlaywright = require('@playwright/test');
  browser = await regularPlaywright.chromium.launch({
    headless,
  });
}