Skip to content

dtinth/pptraas

Repository files navigation

pptraas

Puppeteer, exposed as a web service. Built with Nixpacks.

This project is using Percy.io for visual regression testing.

Introduction

Setting up a service that integrates with Puppeteer is quite a challenge. For example:

  • System dependencies
  • Fonts (does it render text in language X properly?)
  • Emojis
  • Font smoothing

This project aims to solve these issues, expose a simple API, and package all of that into a Docker image that you can deploy into serverless container platforms (like Google Cloud Run or Azure Container Apps) or just run on your own server.

Building image

bin/build

Running the image locally

bin/run

Running the tests locally

The image must be running locally before running the tests.

node test.mjs

This will generate render output in the .data/screenshots directory.

Usage

Make a POST request to the /run endpoint with the following JSON body:

  • code (string): The Puppeteer script to run. It has access to the variable page which is a Puppeteer Page object. Note that await isn’t supported. If you want to use await, wrap it inside an immediately-invoked async function.
  • apiKey (string): When running locally using the bin/run script, the API key is dummy.

If the function call results in a buffer, it will be returned directly. Otherwise, the result will be JSON-encoded and available as result.data in the response.

Example usage:

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "code": "page.goto(\"https://example.com\").then(() => page.screenshot())",
    "apiKey": "dummy"
  }' \
  -o example.png \
  http://localhost:20279/run
View result

Example result

For more examples, see the tests in the test.mjs file.

Deploying

This service can be deployed to any container platform that supports Docker images. The images are available here:

If you specify an API_KEY environment variable, the service will require an API key to be passed in the request body as the apiKey field.

About

Puppeteer exposed as a web service

Resources

Stars

Watchers

Forks

Releases

No releases published