chrome-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,

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 32 (7 by maintainers)

Most upvoted comments

  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.

Fail when run locally without API Gateway (I’m using serverless framework). With serverless + serverless_offline plugin works as expected!

@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)
};

Maybe it’s worth trying to recompile chromium inside that docker container 🤔

@whitehorse0 The exact same code under v2.0.2 and 512MB of RAM on Node 12 works for me:

image

I’ve been struggling a lot with similar issues but the following tutorial saved my life, I just followed all the steps and it works as expected.

https://dev.to/javiertoscano/create-pdf-documents-with-aws-lambda-s3-with-nodejs-and-puppeteer-3phi

{ “errorType”: “Error”, “errorMessage”: “Failed to launch the browser process!\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n”, “trace”: [ “Error: Failed to launch the browser process!”, “”, “”, “TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md”, “”, " at onClose (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)“, " at Interface.<anonymous> (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)”, " at Interface.emit (events.js:327:22)“, " at Interface.close (readline.js:416:8)”, " at Socket.onend (readline.js:194:10)“, " at Socket.emit (events.js:327:22)”, " at endReadableNT (_stream_readable.js:1221:12)“, " at processTicksAndRejections (internal/process/task_queues.js:84:21)” ] }

  • This issue solved for me by giving 1600 MB memory for lambda and 30 sec time out time.
  • It run in the environment of node 10.X and 12.X
  • “chrome-aws-lambda”: “^5.2.1”,
  • “puppeteer-core”: “^5.2.1”

@simsketch Saw this snippet on my email from you (seems like you edited meanwhile):

[0108/195132.808748:ERROR:ssl_client_socket_impl.cc(935)] handshake failed; returned -1, SSL error code 1, net_error -200

You probably need to add ignoreHTTPSErrors: true to your launch() options.