A minimal web app that shows how to use Playwright to extract Open Graph metadata from any URL, render a social-style preview card, and return a PNG screenshot of that card via an Express API.
- Input a URL, validate, and call a backend endpoint to generate a preview.
- Playwright loads the page, extracts OG metadata with sensible fallbacks, then renders a local
/preview-cardtemplate. - Screenshots the preview (1200×630 PNG) and returns it as base64 alongside the metadata.
- UI displays the image, metadata list, error/loading states, and a download button.
- Node.js 18+ recommended
- npm (or another Node package manager)
- Local network access to the target URLs you enter
npm install
npx playwright install chromiumnpm start
# then open http://localhost:3000- Enter a URL (full
http/httpsor just a hostname likeexample.com). - Click Generate Preview.
- Wait for Playwright to extract metadata, build the preview card, and return the screenshot.
- When the image loads, the status bar will show “Preview ready.” with a Download link.
Request:
{ "url": "https://example.com" }Response (200):
{
"metadata": {
"title": "...",
"description": "...",
"image": "...",
"domain": "example.com"
},
"previewImage": "data:image/png;base64,..."
}Example curl:
curl -X POST http://localhost:3000/api/generate-preview \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'- Timeout: pages must load within ~15s; network-idle wait is best-effort.
- Missing metadata: fallbacks use
document.title,meta[name="description"], and the hostname. - Images: if
og:imageis absent or fails to load, the card still renders text-only. - Browser lifecycle: Chromium is launched per request and closed on completion/error.
