Schmidko
Schmidko

Reputation: 810

Get an empty webpage when running Chromeless on AWS Lambda

I want to use the Node.js package Chromeless on a AWS Lambda function. I use two packages: chromless and serverless-chrome On my local machine my test script runs fine. When I deploy it to Lambda I get an empty result for .html() The result is no empty string it is an empty page. (<html><head></head><body></body></html>) There is no error in the CloudWatch Logs. It seems chrome is running fine but can not load the website. NodeJS version is 8.10 and async/await seems to work. Hope someone has an idea.

Code:

const launchChrome = require('@serverless-chrome/lambda');
const { Chromeless } = require('chromeless');

let index = async function handler () {

    await launchChrome({
        port: 9222,
        chromeFlags: [
            '--window-size=1200,800',
            '--disable-gpu',
            '--headless'
        ]
    })
    .then(async (chrome) =>
    {

        const chromeless = new Chromeless(
            {
                launchChrome:false,
                cdp:{host: 'localhost', port: 9222, secure: false}
            }
        );

        const html = await chromeless
            .goto('http://www.google.com')
            .wait(5000)
            .html();
        console.log(html);
        chromeless.end();

    })
};

exports.handler = index;

Logs:

16:39:44 START RequestId: xxx Version: $LATEST
16:39:52 2018-04-05T16:39:52.163Z xxx   <html><head></head><body></body></html>
16:39:52 END RequestId: xxx
16:39:52 REPORT RequestId: xxx
Duration: 7375.83 ms    Billed Duration: 7400 ms Memory Size: 576 MB

Upvotes: 1

Views: 596

Answers (1)

George Haskell
George Haskell

Reputation: 131

This problem has been documented covered pretty well in the Chromeless issues [https://github.com/graphcool/chromeless/issues/414].

There's problem within serverless's dependencies that's causing issues.

To correct it update your serverless/package.json to peg "serverless-plugin-chrome" to version "1.0.0-38".

For example, my dev dependencies look like this:

    "devDependencies": {
    "@types/cuid": "^1.3.0",
    "@types/node": "^9.6.2",
    "serverless": "^1.19.0",
    "serverless-offline": "^3.15.3",
    "serverless-plugin-chrome": "1.0.0-38",
    "serverless-plugin-typescript": "^1.0.0"
  }

Upvotes: 2

Related Questions