Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@serverless-chrome/lambda

adieuadieu3.7kMIT1.0.0-57.2TypeScript support: included

Run headless Chrome/Chromium on AWS Lambda

serverless, chrome, chromium, headless, aws, 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).

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

Added

  • Binary support in AWS Lambda/API Gateway example
  • Build and release tooling shell scripts and Dockerfile's
  • Integration tests and CircleCI setup
  • Complete automation of build/test/release workflows
  • serverless-plugin-chrome: support for limiting Chrome to only select service functions with the custom.chrome.functions parameter.
  • @serverless-chrome/lambda NPM package
  • serverless-plugin-chrome NPM package for Serverless-framework
  • Lots of new and updated documentation
  • CHANGELOG.md.

Changed

  • example Serverless-framework printToPdf function handler to use the Serverless plugin
  • example Serverless-framework captureScreenshot function handler to use the Serverless plugin

[0.5.0] - 2017-03-11, 2017-05-09

Added

  • Headless Chrome headless_shell binary version 60.0.3089.0 built for AWS Lambda
  • Serverless-framework configuration for deploying to AWS Lambda
  • sample printToPdf Lambda function handler
  • sample captureScreenshot Lambda function handler
  • Initial documentation in README.md