Solvedchrome aws lambda [BUG] Failed to launch chrome

Environment

  • chrome-aws-lambda :2
  • puppeteer / puppeteer-core :2
  • OS: osx docker lambda working but lambda runtime node12.x not working
  • Node.js Version:12
  • Lambda / GCF Runtime:Lambda

Expected Behavior

It should work.

Current Behavior

Lambda response

{
  "errorMessage": "Failed to launch chrome!\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md\n",
  "errorType": "Error",
  "stackTrace": [
    "",
    "",
    "TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md",
    "",
    "onClose (/var/task/node_modules/puppeteer-core/lib/Launcher.js:348:14)",
    "Interface.helper.addEventListener (/var/task/node_modules/puppeteer-core/lib/Launcher.js:337:50)",
    "emitNone (events.js:111:20)",
    "Interface.emit (events.js:208:7)",
    "Interface.close (readline.js:370:8)",
    "Socket.onend (readline.js:149:10)",
    "emitNone (events.js:111:20)",
    "Socket.emit (events.js:208:7)",
    "endReadableNT (_stream_readable.js:1064:12)",
    "_combinedTickCallback (internal/process/next_tick.js:138:11)"
  ]
}

Steps to Reproduce

1- save to index.js

const chromium = require('chrome-aws-lambda');

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

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

		let page = await browser.newPage();

		await page.goto(event.url || "https://github.com");

		title = await page.title();
        } catch (error) {
		return context.fail(error);
	} finally {
		if (browser !== null) {
			await browser.close();
		}
	}

	return context.succeed(title)
};

2- npm install puppeteer-core chrome-aws-lambda --save-prod
3- create zip and deploy lambda with runtime node12.x. occur this error.

Thanks,

33 Answers

✔️Accepted Answer

  const browser = await puppeteerExtra.launch({
     headless: chromium.headless,
     ignoreHTTPSErrors: true,
    executablePath:
      process.env.NODE_ENV !== 'production'
        ? undefined
        : await chromium.executablePath,
    defaultViewport: chromium.defaultViewport,
    args: chromium.args,
  });

I got this to work by only using await chromium.executablePath in prod as I know this issue has been resolved in cloud functions. I am not exactly sure why this works and didn't have the time to look into it but it does.

Other Answers:

@kevsersrca Sorry for only following up on this now (I've been travelling).

If this is still an issue to you, could you share some more details? Like RAM allocation and dumpio:

const chromium = require('chrome-aws-lambda');

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

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

		let page = await browser.newPage();

		await page.goto(event.url || "https://github.com");

		title = await page.title();
        } catch (error) {
		return context.fail(error);
	} finally {
		if (browser !== null) {
			await browser.close();
		}
	}

	return context.succeed(title)
};

More Issues: