Menu

I got tired of babysitting Playwright, so I turned it into a small render API
📰

I got tired of babysitting Playwright, so I turned it into a small render API

DEV Community: node·Zakaria Tebani·1 day ago
#JyRo8NJF
#devtonodejs#devto#dev#every#html
Reading 0:00
15s threshold

Every small product I ship ends up needing one of two things: an Open Graph image, or a PDF of some HTML I already have.

Self-hosting Playwright or Puppeteer works . It also:

creeps up in memory until the box runs out

leaves Chrome hanging when a page never finishes loading

captures a GDPR banner over the thing you actually wanted

turns a weekend feature into an ops job

So I put it behind one endpoint, and it's now live as FrameForge : HTML or a URL in, PNG, JPEG or PDF out.

The request

curl -X POST https://95-217-220-34.sslip.io/render \ -H "X-API-Key: $KEY" \ -H "Content-Type: application/json" \ -d '{"html":"<!doctype html><h1>Invoice 1042</h1>","format":"pdf"}' \ -o invoice.pdf

Enter fullscreen mode

Exit fullscreen mode

Swap html for url , or pdf for png / jpeg . width and height go up to 3840 and fullPage captures the whole page.

Design choices I made on purpose

One browser, a new context per request. Sharing tabs is how cookies and memory leaks spread between jobs.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.