Skip to content

scorbit-io/cloudflare-screenshot

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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 1280x720, 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

About

๐ŸŒ‡ Screenshot webpages using Puppeteer on Cloudflare

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%