serverless-chrome-ilkkah
v1.0.20
Published
Run headless Chrome, serverless-ly
Downloads
35
Maintainers
Readme
serverless-chrome
Serverless Chrome contains everything you need to get started running headless Chrome on AWS Lambda (possibly Azure and GCP Functions soon).
The aim of this project is to provide the scaffolding for using Headless Chrome during a serverless function invocation. Serverless Chrome takes care of building and bundling the Chrome binaries and making sure Chrome is running when your serverless function executes. In addition, this project also provides a few example services for common patterns (e.g. taking a screenshot of a page, printing to PDF, some scraping, etc.)
Why? Because it's neat. It also opens up interesting possibilities for using the Chrome DevTools Protocol in serverless architectures and doing testing/CI, web-scraping, pre-rendering, etc.
Contents
- The Project
- Quick Start
- Examples
- Chrome Version
- Testing
- Known Issues / Limitations
- Roadmap
- Projects & Companies using serverless-chrome
- Change log
- Prior Art
The Project
This project contains:
- @serverless-chrome/lambda Node package A standalone module for AWS Lambda which bundles and launches Headless Chrome with support for local development. For use with—but not limited to—tools like Apex, or Claudia.js.
- serverless-plugin-chrome Node package A plugin for Serverless-framework services which takes care of everything for you. You just write the code to drive Chrome.
- Example functions
- Serverless-framework AWS Lambda Node.js functions using
serverless-plugin-chrome
- Serverless-framework AWS Lambda Node.js functions using
- Docker Stuff For building Headless Chrome
Quick Start
Using AWS Lambda, the quickest way to get started is with the Serverless-framework CLI.
First, install serverless
globally:
npm install serverless -g
Then pull down the example service:
serverless install -u https://github.com/adieuadieu/serverless-chrome/tree/master/examples/serverless-framework/aws
Then, you must configure your AWS credentials either by defining AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
environmental variables, or using an AWS profile. You can read more about this on the Serverless Credentials Guide.
In short, either:
export AWS_PROFILE=<your-profile-name>
or
export AWS_ACCESS_KEY_ID=<your-key-here>
export AWS_SECRET_ACCESS_KEY=<your-secret-key-here>
Then, to deploy the service and all of its functions:
serverless deploy
Further details are available in the Serverless Lambda example.
Examples
A collection of example functions for different providers and frameworks.
Serverless-framework
Serverless-framework Some simple functions for the Serverless-framework on AWS Lambda. It includes the following example functions:
- Print to PDF
- Capture Screenshot
- Page-load Request Logger
Chrome Version
The current Chrome build is:
- Browser: HeadlessChrome/61.0.3135.0
- Protocol-Version: 1.2
- User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/61.0.3135.0 Safari/537.36
- V8-Version: 6.1.201
- WebKit-Version: 537.36 (@c671506faf285787f1c0377f90c8129a1a40a347)
Testing
Test with yarn test
or just yarn ava
to skip the linter.
Known Issues / Limitations
- Hack to Chrome code to disable
/dev/shm
. Details here. /tmp
size on Lambda is only about 500MB.- For steady/predictable loads, it might not be the most cost efficient to do this on Lambda vs. EC2
Roadmap
1.1
- Support for Google Cloud Functions
- Example for Apex
- Example for Claudia.js
1.2
- DOM manipulation and scraping example handler
Future
- Support for Azure Functions (Once Headless Chrome supports Windows)
Projects & Companies using serverless-chrome
Tell us about your project on the Wiki!
Change log
See the CHANGELOG
Prior Art
This project was inspired in various ways by the following projects: