Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 3.96 KB

README.md

File metadata and controls

59 lines (37 loc) · 3.96 KB

Cloudflare Screenshot

Screenshot webpages to render social media cards on-the-fly using Puppeteer; largely based on how Pieter generates shareable pictures for Nomad List.

Coworkations 📄 HTML 🖼️ PNG Hacker Paradise: Cape Town South Africa 📄 HTML 🖼️ PNG
Nomad Cruise VI: Spain To Greece 📄 HTML 🖼️ PNG PACK: Ubud Bali 📄 HTML 🖼️ PNG

Setup

Deploy the worker to Cloudflare and mount it on a route like example.com/screenshots/*, then visit screenshots/path/to/something.png for a capture of path/to/something.

Deploy to Cloudflare Workers

Usage

Screenshots can be of any webpage, you can pass query params through to your backend if you need to toggle behaviors like to force dark mode on/off, or disable things like Intercom:

🖼 PNG (Cloudflare request) 📄 HTML (webserver request)
https://coworkations.com/screenshots/hacker-paradise.png https://coworkations.com/hacker-paradise
https://steve.ly/screenshots/home.png?dark=on https://steve.ly/home?dark=on

For social media cards you might want to render a template that works well on social media:

🖼 PNG (Cloudflare request) 📄 HTML (webserver request)
https://coworkations.com/screenshots/cards/hacker-paradise.png https://coworkations.com/cards/hacker-paradise
https://coworkations.com/screenshots/cards/pack/ubud-bali-2.png https://coworkations.com/cards/pack/ubud-bali-2

The default dimensions for screenshots are 1200x630, which works well for most social media cards. You can specify different dimensions via the URL, e.g., screenshots/1024x768/path/to/something.png.

Additionally, you can adjust the pixel density by appending @2x, @3x, or @4x to the filename, e.g., screenshots/path/to/[email protected].

If you want to configure some query params to always pass through to your backend, you can set the QUERY_PARAMS environment variable and they will be appended to every webserver request.

Markup

You’ll probably want meta tags something like these:

<meta itemprop="image" content="https://coworkations.com/screenshots/cards/coworkations.png">
<meta property="og:image" content="https://coworkations.com/screenshots/cards/coworkations.png">
<meta name="twitter:image" content="https://coworkations.com/screenshots/cards/coworkations.png">

Debugging