This package has been deprecated

Author message:

Use https://github.com/alixaxel/chrome-aws-lambda instead

@browserless/aws-lambda-chrome

1.11.0 • Public • Published

@browserless/aws-lambda-chrome

Last version Dependency status Dev Dependencies Status NPM Status Donate

Chrome (v72.0.3582.0) binary compatible with AWS Lambda.

Install

$ npm install @browserless/aws-lambda-chrome --save

This package content a binary compressed version of Chrome compatible with AWS Lambda.

Usage

Note: Ensure to use --disable-dev-shm-usage flag.

It has been designed to be used with puppeteer, specially using browserless.

For example, let create a get-browserless.js file with the follow content:

const browserless = require('browserless')

const getChromePath = require('@browserless/aws-lambda-chrome')({
  path: '/tmp'
})

const isLambda = !!process.env.LAMBDA_TASK_ROOT
const getExecutablePath = async () => (isLambda ? getChromePath() : undefined)

module.exports = async () =>
  browserless({
    ignoreHTTPSErrors: true,
    args: [
      '--disable-gpu',
      '--single-process',
      '--no-zygote',
      '--no-sandbox',
      '--disable-dev-shm-usage',
      '--hide-scrollbars'
    ],
    executablePath: await getExecutablePath()
  })

Then in your code just call the snippet, like:

;(async () => {
  const getBrowserless = require('./get-browserless')
  const { screenshot } = await getBrowserless() // serverless!
})()

The first time it will be used it will decompress the file. After that, the decompress version will be reused at next successive calls.

API

constructor([options])

options

path

Type: string
Default: 'dist'

Where extract the binary.

FAQ

Q: How to use a newer version of Node on AWS Lambda?

Currently, AWS Lambda supports Node.js 6.10 and v8.10.

We recommend using the last Node.js version available with your Lambda function.

If you need to provide your own Node.js executable, here a bash script for do that:

#!/bin/bash

NODE_BIN=`curl -sL https://semver.io/node/resolve/8`-linux-x64

echo "Downloading $NODE_BIN binary file"

curl -sL https://nodejs.org/dist/latest-v8.x/node-v$NODE_BIN.tar.gz | tar -xz
mkdir -p bin
mv node-v$NODE_BIN/bin/node bin/node
rm -rf node-v$NODE_BIN

echo "Added \`bin/node\` as node-v$NODE_BIN"

You can run the script as postinstall and then user the binary created for run your microservice:

{
  "scripts": {
  "postinstall": "./scripts/download_node.sh",
  "start": "NODE_ENV=production ./bin/node ./node_modules/micro/bin/micro.js --host localhost --port $PORT index.js"
  }
}

Q: How Can I create my own Headless Chrome binary?

The idea behind the project is to ship a production-ready of last Chrome version available.

For do that, is necessary compile Chromium into a AWS Lambda compatible machine, normally a EC2.

We recommend the followings projects for get instructions to do that:

Related

License

aws-lambda-chrome © Kiko Beats, Released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @kikobeats

Package Sidebar

Install

npm i @browserless/aws-lambda-chrome

Weekly Downloads

1

Version

1.11.0

License

MIT

Unpacked Size

47.4 MB

Total Files

7

Last publish

Collaborators

  • kikobeats