shelfio / chrome-aws-lambda-layer

58 MB Google Chrome to fit inside AWS Lambda Layer compressed with Brotli
MIT License
637 stars 45 forks source link

CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later. #31

Closed ramirocastillo93 closed 2 years ago

ramirocastillo93 commented 3 years ago
{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "Error: The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.",
  "trace": [
    "Runtime.UnhandledPromiseRejection: Error: The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.",
    "    at process.<anonymous> (/var/runtime/index.js:35:15)",
    "    at process.emit (events.js:314:20)",
    "    at processPromiseRejections (internal/process/promises.js:209:33)",
    "    at processTicksAndRejections (internal/process/task_queues.js:98:32)"
  ]
}

I'm trying to make this run but can't cause of that message. My code is as follows:

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

exports.handler = function (event, context, callback) {

  (async () => {
    const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
    const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};
    const runnerResult = await lighthouse('https://google.com', options);

    // `.lhr` is the Lighthouse Result as a JS object
    console.log('Report is done for', runnerResult.lhr.finalUrl);
    console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);

    await chrome.kill();
  })()
};

And have an env variable called CHROME_PATH which has this path assigned /opt/nodejs/node_modules/chrome-aws-lambda/chromium.br

vladholubiev commented 2 years ago
-    const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
+    const chrome = await chromeLauncher.launch({chromeFlags: ['--headless'], chromePath: await chromium.executablePath});