talira

@sparticuz/chromium

Chromium for Serverless Platforms

open sourceMITself-hostablefree

@sparticuz/chromium is a Brotli-compressed build of Chromium's headless shell for serverless platforms such as AWS Lambda, with the code that decompresses it into /tmp and a set of launch arguments tuned for those environments. It provides only the browser: you drive it with puppeteer-core (Puppeteer) or playwright-core (Playwright) by passing chromium.args and await chromium.executablePath() to their launch call. Versions follow Chromium's major versions rather than semver, so you install the one that matches your puppeteer-core. The npm package ships x64 binaries; @sparticuz/chromium-min leaves them out so they load from a Lambda layer or a pack hosted on S3, which is also how arm64 works. It succeeds the author's @sparticuz/chrome-aws-lambda, itself a fork of chrome-aws-lambda, and Puppeteer's troubleshooting guide points to it for AWS Lambda.

Problems it solves

  • puppeteer's bundled Chrome pushes my Lambda deployment past the 250 MB unzipped limit
  • Chrome won't launch inside Lambda because the runtime is missing the shared libraries it needs
  • chrome-aws-lambda is years out of date and doesn't work with current puppeteer-core versions
  • take screenshots of web pages from a serverless function
  • run Playwright's Chromium inside an AWS Lambda function
  • turn HTML into PDFs with headless Chrome inside a Node.js AWS Lambda function
  • puppeteer-core on Lambda needs a Chromium binary built for Amazon Linux
  • scrape JavaScript-rendered pages from a Lambda function on a schedule
  • my Lambda zip is over the 50 MB direct upload limit once a headless browser is in it
  • download the headless browser from S3 on cold start instead of bundling it in the function
  • share one Chromium build across many Lambda functions as a layer
  • run headless Chrome on Graviton arm64 Lambda functions
  • print pages to PDF with headless Chromium in a Netlify function
  • screenshots from my Lambda show empty boxes for emoji and Chinese text: add fonts to headless Chrome
  • Error: The input directory /var/task/bin does not exist after bundling my Lambda with esbuild

View all 18 problems

Features

  • Brotli-compressed Chromium headless shell that decompresses into /tmp at startup
  • chromium.args: recommended Chromium flags for serverless environments
  • chromium.executablePath(): path to the extracted binary, from the package, a local folder or a remote pack URL
  • works with puppeteer-core and playwright-core
  • works with all currently supported AWS Lambda Node.js runtimes
  • @sparticuz/chromium-min: same code without the binaries, for layers or remote packs
  • Lambda layer zips and pack tars for x64 and arm64 in each GitHub release
  • ships Open Sans (Latin, Greek, Cyrillic); extra fonts from /opt/fonts, /var/task/fonts or /tmp/fonts
  • WebGL through SwiftShader/ANGLE, which setGraphicsMode = false turns off
  • Makefile target to build your own Lambda layer
View 1 more
  • examples for AWS SAM, the Serverless Framework, Lambda layers and Netlify

Limitations

  • Doesn't run on macOS or Windows: the bundled Chromium is compiled for Linux only, so local development needs a separately installed Chrome or Chromium1
  • Doesn't include arm64 binaries in the npm package: arm64 (Graviton) needs @sparticuz/chromium-min with the layer or pack from a GitHub release1
  • Doesn't produce tagged (accessible) PDFs: you have to recompile Chromium with a patch and load it through @sparticuz/chromium-min1
  • Doesn't support headful mode or Chrome's new headless mode: it's built on headless_shell, with no GUI1