🌜
🌞
serverless-plugin-chrome

serverless-plugin-chrome

v1.0.0-55.3

A Serverless-framework plugin that takes care of running headless Chrome so that you can move on with getting things done.

npm install serverless-plugin-chrome

README

Serverless-framework Headless Chrome Plugin

A Serverless-framework plugin which bundles the @serverless-chrome/lambda package and ensures that Headless Chrome is running when your function handler is invoked.

npm

Contents

Installation

Install with yarn:

yarn add --dev serverless-plugin-chrome

Install with npm:

npm install --save-dev serverless-plugin-chrome

Requires Node 12 runtime.

Setup

Add the following plugin to your serverless.yml:

plugins:
  - serverless-plugin-chrome

Then, in your handler code.. Do whatever you want. Chrome will be running!

const CDP = require('chrome-remote-interface')

module.exports.hello = (event, context, callback, chrome) => {
  // Chrome is already running!

  CDP.Version()
    .then(versionInfo => {
      callback(null, {
        statusCode: 200,
        body: JSON.stringify({
          versionInfo,
          chrome,
        }),
      })
    })
    .catch(error => {
      callback(null, {
        statusCode: 500,
        body: JSON.stringify({
          error,
        }),
      })
    })
}

Further details are available in the Serverless Lambda example.

Examples

Example functions are available here. They include:

  • Screenshot capturing handler: takes a picture of a URL
  • print-to-PDF handler: turns a URL into a PDF

Local Development

Local development is supported. You must install the chrome-launcher package in your project. A locally installed version of Chrome will be launched.

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.

Configuration

You can pass custom flags with which to launch Chrome using the custom section in serverless.yml. For example:

plugins:
  - serverless-plugin-chrome

custom:
  chrome:
    flags:
      - --window-size=1280,1696 # Letter size
      - --hide-scrollbars
      - --ignore-certificate-errors
    functions:
      - enableChromeOnThisFunctionName
      - mySuperChromeFunction

It is also possible to enable Chrome on only specific functions in your service using the custom.chrome.functions configuration. For example:

custom:
  chrome:
    functions:
      - enableChromeOnThisFunctionName
      - mySuperChromeFunction

You can enable debugging/logging output by specifying the DEBUG env variable in the provider section of serverless.yml. For example:

provider:
  name: aws
  runtime: nodejs12.x
  environment:
    DEBUG: '*'

plugins:
  - serverless-plugin-chrome

Using with other plugins

Load order is important.

For example, if you're using the serverless-webpack plugin, your plugin section should be:

plugins:
  - serverless-plugin-chrome # 1st
  - serverless-webpack

However, with the serverless-plugin-typescript plugin, the order is:

plugins:
  - serverless-plugin-typescript
  - serverless-plugin-chrome # 2nd

Troubleshooting

I keep getting a timeout error when deploying and it's really annoying.

Indeed, that is annoying. I've had the same problem, and so that's why it's now here in this troubleshooting section. This may be an issue in the underlying AWS SDK when using a slower Internet connection. Try changing the AWS_CLIENT_TIMEOUT environment variable to a higher value. For example, in your command prompt enter the following and try deploying again:

export AWS_CLIENT_TIMEOUT=3000000
Aaaaaarggghhhhhh!!!

Uuurrrggghhhhhh! Have you tried filing an Issue?

Release Notes

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

1.0.0-46
By Cosimo Botsimo • Published on May 18, 2018

This is an automated release.

chromium 67.0.3396.48 (beta channel) for amazonlinux:2017.03 chromium 68.0.3432.3 (dev channel) for amazonlinux:2017.03 chromium 66.0.3359.181 (stable channel) for amazonlinux:2017.03

General

License
MIT
Typescript Types
None found
Tree-shakeable
Yes

Popularity

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

Maintenance

Commits
11/2110/2201
Last Commit
Open Issues
31
Closed Issues
186
Open Pull Requests
28
Closed Pull Requests
36

Versions

Versions Released
11/2110/2201
Latest Version Released
Jan 20, 2020
Current Tags
latest1.0.0-55.3

Contributors

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