npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-plugin-chrome

v1.0.0-55.3

Published

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

Downloads

2,899

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

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

Uuurrrggghhhhhh! Have you tried filing an Issue?