question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for handler()

See original GitHub issue

Hi,

I’ve got the next error with serverless-chrome-plugin

ERROR Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for handler() handler. { functions: [ 'processsqsevent' ], flags: [ '--window-size=1280,1696', '--hide-scrollbars' ], chromePath: '/var/task/headless-chromium' } Error: Unable to start Chrome. If you have the DEBUG env variable set,there will be more in the logs. at /var/task/api/process_sqs.js:257:5970 at Generator.throw (<anonymous>) at n (/var/task/api/process_sqs.js:257:5007) at /var/task/api/process_sqs.js:257:5129 at processTicksAndRejections (internal/process/task_queues.js:93:5)

Debug mode shows the next errors:

INFO @serverless-chrome/lambda: Error trying to spawn chrome: Error: connect ECONNREFUSED 127.0.0.1:9222 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 9222 } INFO @serverless-chrome/lambda: stderr log: /var/task/headless-chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory Node version 12.13.1

Any thoughts? Could anybody help?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:6

github_iconTop GitHub Comments

10reactions
evgeniyannenkovcommented, Jan 27, 2020

Hi there!

Based on the fact that I did not find the answer to my question, the fastest way to restore broken functionality in my project is to migrate to chrome-aws-lambda.

That’s my way:

  1. Add chrome-aws-lambda to the project;
  2. Add this package to webpack externals;
module.exports = {
    externals : ['chrome-aws-lambda'],
};

  1. Create infrastructure to build chrome artifacts (I’ve used this solution https://github.com/devasur/chrome-aws-lambda-layer);

build_chrome_layer.sh

#!/bin/bash
set -e
rm -rf chrome-aws-lambda
git clone --depth=1 https://github.com/alixaxel/chrome-aws-lambda.git
cd chrome-aws-lambda
make chrome_aws_lambda.zip
ls -lah chrome_aws_lambda.zip
echo -e "\033[33mLayer created successfully...\033[0m"

copy_chrome_artifact.sh

#!/bin/bash
set -e
mv chrome-aws-lambda/chrome_aws_lambda.zip .serverless/chrome_aws_lambda.zip
rm -rf chrome-aws-lambda
echo -e "\033[33mArtifact copied successfully...\033[0m"
  1. I’ve used the serverless-scriptable-plugin to execute my scripts during the build; serverless.yaml
custom                  :
  webpack               :
    webpackConfig       : 'webpack.config.js'
  scriptHooks           :
    before:package:createDeploymentArtifacts:
      - scripts/build_chrome_layer.sh
    after:package:createDeploymentArtifacts:
      - scripts/copy_chrome_artifact.sh
  1. Also we should add chrome artifact as a layer to our executable lambda function; serverless.yaml
layers                  :
  chromePreBuilt        :
    package             :
      artifact          : .serverless/chrome_aws_lambda.zip

functions               :
  makeScreenshot       :
    layers              :
      - { Ref: ChromePreBuiltLambdaLayer}
    handler             : api/makeScreenshot.handler
  1. Then you can use the library to launch chrome the next way:
const chromium = require('chrome-aws-lambda');

const args = [
    '--remote-debugging-port=9222',
    '--window-size=1280,1696'
];

module.exports = async () => {
    try {
        const executablePath = await chromium.executablePath;
        const options = {
            args            : chromium.args.concat(args),
            defaultViewport : chromium.defaultViewport,
            headless        : chromium.headless,
            executablePath
        };
        return chromium.puppeteer.launch(options);
    } catch (error) {
        console.error('Error launching Chrome: ', error);
        return error;
    }
};

That’s it. Hope it will be helpful.

2reactions
evgeniyannenkovcommented, Sep 22, 2020

@godrose Morning! This error is due the fact that you are trying to install a lot of dependencies. Please, check the lambda layers documentation to avoid this issue. https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serverless deploy issue with Headless chrome
'Error occured in serverless-plugin-chrome wrapper when trying to ' + 'ensure Chrome for syncToDb() handler.', options, error )
Read more >
@serverless-chrome/lambda - npm package | Snyk
Run headless Chrome/Chromium on AWS Lambda For more information about how to use ... 'Error occured in serverless-plugin-chrome wrapper when trying to '...
Read more >
serverless-chrome - Bountysource
build/src/handlers/screenshot.js Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for default() handler.
Read more >
serverless-plugin-chrome-hocnv - npm
A Serverless-framework plugin that takes care of running headless Chrome so that you can move on with getting things done.
Read more >
Resolve "ClassNotFoundExeption" errors from Java Lambda ...
When I try to invoke my Java AWS Lambda function, I get "ClassNotFoundException" or "NoSuchMethodError" errors. How do I resolve these ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found