Puppeteer, exposed as a web service. Built with Nixpacks.
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.
bin/build
bin/run
The image must be running locally before running the tests.
node test.mjs
This will generate render output in the .data/screenshots
directory.
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 variablepage
which is a PuppeteerPage
object. Note thatawait
isn’t supported. If you want to useawait
, wrap it inside an immediately-invoked async function.apiKey
(string): When running locally using thebin/run
script, the API key isdummy
.
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
For more examples, see the tests in the test.mjs
file.
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.