Skip to content

HOWTO: Local Development

Alix Axel edited this page Oct 13, 2019 · 8 revisions

This project is compiled specifically for AWS Lambda (Linux x64)

Therefore the binary might not be compatible with your local system, making development trickier.

Background

The headless getter returns a boolean indicating if we are running on a serverless environment.

If it returns false, it will cause the following side-effects:

  • the args getter will return different flags
    • --single-process flag will be omitted
    • --start-maximized flag with be present
  • the defaultViewport getter will return a different configuration
    • width=0 (maximized) instead of width=1920
    • height=0 (maximized) instead of height=1080
  • the font() method becomes no-op to avoid polluting the user space
  • the executablePath getter returns null and Chromium / SwiftShader will not be extracted

Environment Variables

It's possible to trick the headless getter into returning true by setting any of the following:

  • AWS_LAMBDA_FUNCTION_NAME (used by AWS Lambda)
  • FUNCTION_NAME (used by Google Cloud Functions)
  • FUNCTION_TARGET (used by Google Cloud Functions)

Additionally, to use the bundled iltorb module, you need to be running Node 8.10 and set:

  • AWS_EXECUTION_ENV=AWS_Lambda_nodejs8.10

Note that this approach is not recommended, as it may not be compatible with your system.

On Node v10.16.0+, native Brotli is used instead, so the bundled iltorb is no longer necessary.


Workaround

The suggested workaround is to install puppeteer as a development dependency.

npm install puppeteer-core chrome-aws-lambda --save-prod
npm install puppeteer --save-dev

The provided puppeteer getter will return the resolved puppeteer package.

First it will try to load puppeteer and, only if that's not available, fallback to loading puppeteer-core - if puppeteer-code is also not available, then a MODULE_NOT_FOUND error is thrown.

As long as your deployment pipeline skips bundling devDependencies, this approach allows us to rely on puppeteer for local development and puppeteer-core for production deployments.

Clone this wiki locally
You can’t perform that action at this time.