🌜
🌞
@serverless-chrome/lambda

@serverless-chrome/lambda

v1.0.0-57.2

Run headless Chrome/Chromium on AWS Lambda

npm install @serverless-chrome/lambda

README

serverless-chrome/lambda

Standalone package to run Headless Chrome on AWS Lambda's Node.js (6.10+) runtime.

npm

Contents

  1. Installation
  2. Setup
  3. Local Development
  4. Framework Plugins
  5. Specifying Chromium Channel

Installation

Install with yarn:

yarn add @serverless-chrome/lambda

Install with npm:

npm install --save @serverless-chrome/lambda

If you wish to develop locally, you also need to install chrome-launcher:

npm install --save-dev chrome-launcher

Setup

Use in your AWS Lambda function. Requires Node 6.10.

const launchChrome = require('@serverless-chrome/lambda')
const CDP = require('chrome-remote-interface')

module.exports.handler = function handler (event, context, callback) {
  launchChrome({
    flags: ['--window-size=1280,1696', '--hide-scrollbars']
  })
  .then((chrome) => {
    // Chrome is now running on localhost:9222

    CDP.Version()
      .then((versionInfo) => {
        callback(null, {
          versionInfo,
        })
      })
      .catch((error) => {
        callback(error)
      })
  })
  // Chrome didn't launch correctly 😒
  .catch(callback)
}

Local Development

Local development is supported. In a non-lambda environment, the package will use chrome-launcher to launch a locally installed Chrome. You can also pass your own chromePath:

launchChrome({ chromePath: '/my/local/chrome/path' })

Command line flags (or "switches")

The behavior of Chrome does vary between platforms. It may be necessary to experiment with flags to get the results you desire. On Lambda default flags are used, but in development no default flags are used.

The package has zero external dependencies required for inclusion in your Lambda function's package.

Framework Plugins

There are plugins which bundle this package for easy deployment available for the following "serverless" frameworks:

Specifying Chromium Channel

This package will use the latest stable-channel build of Headless Chromium for AWS Lambda. To select a different channel (beta or dev), export either an environment variable NPM_CONFIG_CHROMIUM_CHANNEL or add chromiumChannel to the config section of your package.json:

Your package.json:

{
  "name": "my-cool-project",
  "version": "1.0.0",
  "config": {
    "chromiumChannel": "dev"  <-- here
  },
  "scripts": {

  },
  "description": {

  }
}

Note: the dev channel is almost canary, so use dev if you're looking for the Canary channel.

You can skip download entirely with NPM_CONFIG_SERVERLESS_CHROME_SKIP_DOWNLOAD or setting skip_download in the config section of your package.json

Caution: We test and develop features against the stable channel. Using the beta or dev channel versions of Chromium may lead to unexpected results, especially in relation to the Chrome DevTools Protocol (which is used by tools like Chromeless and Puppeteer).

Release Notes

1.0.0-57
By Marco LΓΌthy β€’ Published on October 23, 2020

Big thank you to @skunkworker for fixing the Chromium builds! πŸ™‡

chromium 87.0.4280.27 (beta channel) for Amazon Linux 2 chromium 88.0.4298.4 (dev channel) for Amazon Linux 2 chromium 86.0.4240.111 (stable channel) for Amazon Linux 2

1.0.0-55
By Cosimo Botsimo β€’ Published on September 6, 2018

This is an automated release.

chromium 69.0.3497.81 (beta channel) for amazonlinux:2017.03 chromium 70.0.3534.4 (dev channel) for amazonlinux:2017.03 chromium 69.0.3497.81 (stable channel) for amazonlinux:2017.03

1.0.0-54
By Cosimo Botsimo β€’ Published on August 11, 2018

This is an automated release.

chromium 69.0.3497.32 (beta channel) for amazonlinux:2017.03 chromium 70.0.3514.0 (dev channel) for amazonlinux:2017.03 chromium 68.0.3440.106 (stable channel) for amazonlinux:2017.03

1.0.0-53
By Cosimo Botsimo β€’ Published on August 3, 2018
  • #154 β€” Check that process exists before assuming Chrome is running β€” thanks @defendertx!

chromium 69.0.3497.23 (beta channel) for amazonlinux:2017.03 chromium 69.0.3497.23 (dev channel) for amazonlinux:2017.03 chromium 68.0.3440.84 (stable channel) for amazonlinux:2017.03

1.0.0-52
By Cosimo Botsimo β€’ Published on August 3, 2018

This is an automated release.

chromium 69.0.3497.23 (beta channel) for amazonlinux:2017.03 chromium 69.0.3497.23 (dev channel) for amazonlinux:2017.03 chromium 68.0.3440.84 (stable channel) for amazonlinux:2017.03

1.0.0-51
By Cosimo Botsimo β€’ Published on July 27, 2018

This is an automated release.

chromium 68.0.3440.75 (beta channel) for amazonlinux:2017.03 chromium 69.0.3497.12 (dev channel) for amazonlinux:2017.03 chromium 68.0.3440.75 (stable channel) for amazonlinux:2017.03

1.0.0-50
By Cosimo Botsimo β€’ Published on July 15, 2018

This is an automated release.

chromium 68.0.3440.59 (beta channel) for amazonlinux:2017.03 chromium 69.0.3486.0 (dev channel) for amazonlinux:2017.03 chromium 67.0.3396.99 (stable channel) for amazonlinux:2017.03

1.0.0-49
By Cosimo Botsimo β€’ Published on June 15, 2018

This is an automated release.

chromium 68.0.3440.25 (beta channel) for amazonlinux:2017.03 chromium 69.0.3452.0 (dev channel) for amazonlinux:2017.03 chromium 67.0.3396.87 (stable channel) for amazonlinux:2017.03

1.0.0-48
By Cosimo Botsimo β€’ Published on June 10, 2018

This is an automated release.

chromium 68.0.3440.17 (beta channel) for amazonlinux:2017.03 chromium 69.0.3452.0 (dev channel) for amazonlinux:2017.03 chromium 67.0.3396.79 (stable channel) for amazonlinux:2017.03

1.0.0-47
By Cosimo Botsimo β€’ Published on June 1, 2018

This is an automated release.

chromium 67.0.3396.62 (beta channel) for amazonlinux:2017.03 chromium 68.0.3440.7 (dev channel) for amazonlinux:2017.03 chromium 67.0.3396.62 (stable channel) for amazonlinux:2017.03

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
2,708
Community Interest
2,918
Number of Forks
301

Maintenance

Commits
10/219/2202
Last Commit
Open Issues
31
Closed Issues
186
Open Pull Requests
28
Closed Pull Requests
36

Versions

Versions Released
10/219/2201
Latest Version Released
Oct 24, 2020
Current Tags
latest1.0.0-57.2

Contributors

adieuadieu
adieuadieu
Commits: 377
botsimo
botsimo
Commits: 231
skunkworker
skunkworker
Commits: 14
willfarrell
willfarrell
Commits: 7
benjaminwood
benjaminwood
Commits: 5
orporan
orporan
Commits: 3
mwillfox
mwillfox
Commits: 3
akashmohapatra
akashmohapatra
Commits: 2
qubyte
qubyte
Commits: 2
dobesv
dobesv
Commits: 1
ljosa
ljosa
Commits: 1
zachschultz
zachschultz
Commits: 1
ka2jun8
ka2jun8
Commits: 1
jaimeiniesta
jaimeiniesta
Commits: 1
krtek
krtek
Commits: 1