Item images
Every card should have a big image (SI-527). Code: packages/core/src/feeds/page-image.ts, firstContentImage() in normalize.ts, the cache in packages/core/src/images/cache.ts, and the screenshots in packages/core/src/images/screenshots.ts.
Where an item’s image comes from
In this order, the first one found wins:
- The feed’s media:
media:contentwith an image,media:thumbnail, an image enclosure, or the episode’s iTunes image. YouTube items: see youtube.md. - The first large image in the item’s content. The first
<img>whose stated width and height, if any, are at least 120 px. Trackers, emoji, avatars, icons, share buttons and SVGs are skipped. - The share image of the article’s page:
og:image, thentwitter:image, then<link rel="image_src">, read from the page’s<head>(at most the first 256 KB). Only when the fetch stores new items, for the 8 newest items without an image that were published in the last 14 days. A first import of a thousand feeds therefore doesn’t fetch tens of thousands of pages. - A screenshot of the page (SI-543), taken by a headless Chromium in the background. See Screenshots.
- No image: the card shows its layout without an image.
Steps 1 and 2 happen when the feed is parsed. Step 3 happens when new items are stored, so a refetch costs nothing. The item keeps the URL of the original image (items.image_url). Step 4 happens later, in a queue. A screenshot never becomes the item’s image_url, so Raindrop doesn’t get it as a cover. Only the card shows it.
What to expect: 30 well-known feeds (news in English and German, tech blogs, personal blogs, link blogs, comics) gave an image for 90% of their recent items (167 of 186): 62% from the feed or content, 27% from the page. Pages behind a cookie-consent wall show no share image to Hotaru: golem.de gave none, and without it the sample was at 94%. Link blogs whose items point to pages without a share image get fewer.
Screenshots
For an item that ends up with no image, a queue in the server takes a screenshot of its page: the visible part of a 1280 × 720 window, stored in the cache like every image (1200 px wide, WebP). The card loads it from /images/<item id> as usual. The stream’s items say screenshot: true when there is one.
Which items: published in the last 14 days, a web page (not a video), no image of its own, and in the stream of someone who follows the source: not filtered out by the gate, not muted, source not paused. The newest go first. An item waits for the extract stage, which may still find the article’s image, but at most an hour. A failed page is tried once more after 6 hours, then the card goes without.
Where the browser runs. In production, in its own container: the official Playwright image, running a browser server that Hotaru connects to (SCREENSHOT_BROWSER_URL). Pages are anyone’s, and they run with JavaScript. A browser exploit then lands in a container with no access to /data, and Docker’s limits on that container cap its CPU and memory. Chromium’s own sandbox doesn’t work in a default Docker container: it needs user namespaces or CAP_SYS_ADMIN, and the app container shouldn’t get those. In development, Hotaru starts the Chromium that Playwright installed for the e2e tests (pnpm --filter @hotaru/web exec playwright install chromium), or the one in SCREENSHOT_BROWSER, with its sandbox on. SCREENSHOT_SANDBOX=off turns the sandbox off for a local browser, but only do that where nothing else matters. Setup: deployment.md.
Staying small. The VPS runs other apps, so the queue works within limits:
- One page at a time, in one browser with one renderer process, a 256 MB JavaScript heap, no GPU, no video, audio, web sockets or service workers.
- Memory and CPU of the browser container:
mem_limitandcpusin its Compose file. Docker enforces them. - Memory of a local browser: its processes are measured four times a second (
/procon Linux,pselsewhere). OverSCREENSHOT_MAX_MEMORY_MB, the browser is killed and the page counts as failed. A remote browser’s processes can’t be seen from the app, so this check applies to a local one only. - CPU, for both: after each page the queue waits long enough that its average stays at
SCREENSHOT_CPU_PERCENTof one core. A page that took 4 s at 25 % means a 12 s pause. - Time: a page gets
SCREENSHOT_TIMEOUT_MS, from start to picture. Then the browser is stopped. - The machine first: no screenshot while less than
SCREENSHOT_MIN_FREE_MBof memory is free, or the load average per core is aboveSCREENSHOT_MAX_LOAD. - A local browser starts on demand, closes after two idle minutes, and starts fresh every 40 pages. When the browser can’t start or can’t be reached, the queue waits 10 minutes and doesn’t count it against the items.
Cookie banners. The scripts of the common consent managers (OneTrust, Cookiebot, Usercentrics, Didomi, Quantcast, Sourcepoint, TrustArc and others) are blocked, so their banners never draw. Banners with the usual names are hidden, and a visible button such as “Accept all” or “Alle akzeptieren” is clicked. Then whatever still stands in front of the page goes: fixed layers covering more than 30 % of the window, modal dialogs, and fixed bars along the bottom edge (cookie notices, offers). A page that sends the browser to a consent page instead (golem.de, Yahoo, Google) counts as failed, and so does one that shows nothing (one color).
No way into the network. Users can add any URL, so the browser gets the same rule as the feed fetcher: it must never reach this machine or the private network. Every request the browser makes (page, scripts, images, redirects) is answered by Hotaru’s own fetcher in the app, which refuses private, loopback and link-local addresses at every connection, also after DNS rebinding, and checks IP addresses at every redirect. Anything the interception doesn’t see goes to a proxy that doesn’t exist, and WebRTC can’t use UDP. The browser container sits on a network it shares only with the app.
The cache
Images never load from the original site. Cards and the reader load /images/<item id>:
- The first request downloads the image (up to 15 MB, through the same fetcher as feeds, so private addresses stay blocked). It is rotated upright, scaled down to 1200 px wide and stored as WebP (quality 72). That’s sharp on a 2× screen for a card at most ~700 px wide, about 50 KB on average (48 images from those feeds took 2.3 MB).
- Later requests read the file. The browser keeps it for 30 days (
private, immutable). - Several cards asking for the same image at once download it once.
- An image that can’t be had (gone, not an image, smaller than 100 px on a side) gives a
404, so the card shows its layout without an image. That answer is kept for a day before the download is tried again. - The route is behind the login, and serves only images of items in the user’s own stream.
Screenshots share the cache, its size limit and its cleanup. When the cleanup deletes a screenshot, the next request for it forgets it, and the queue takes a new one while the item is recent.
Files live in images/ next to the database, /data/images in production, on the same volume. They’re named by a hash of the image URL, in 256 subfolders.
Size limit and cleanup: the scheduler checks the cache daily, with the content retention. When it is larger than IMAGE_CACHE_MAX_MB (default 2048), the least recently used images are deleted until it is at 90% of the limit. Reading an image counts as using it (its file time is refreshed at most once a day). Failure markers older than a day are deleted too. A deleted image is simply downloaded again when someone scrolls to it.
The cache isn’t backed up: Litestream backs up the database only (backups.md), and every image can be fetched again.
Settings
| Variable | Default | |
|---|---|---|
IMAGE_CACHE_MAX_MB |
2048 |
Largest size of the cache |
IMAGE_CACHE_DIR |
images/ next to the database |
Where the files go |
SCREENSHOTS |
off | on: take screenshots of pages for items without an image |
SCREENSHOT_BROWSER_URL |
unset | The browser container’s address, ws://<container>:3001/<secret path>. Unset: start a local Chromium |
SCREENSHOT_BROWSER |
Playwright’s Chromium | A local Chromium to run instead |
SCREENSHOT_SANDBOX |
on | off: a local Chromium without its sandbox |
SCREENSHOT_MAX_MEMORY_MB |
768 |
Most memory a local browser may use, all its processes |
SCREENSHOT_CPU_PERCENT |
25 |
Average share of one core, 1–100 |
SCREENSHOT_TIMEOUT_MS |
20000 |
Most time for one page |
SCREENSHOT_MIN_FREE_MB |
512 |
No screenshot while less memory is free |
SCREENSHOT_MAX_LOAD |
0.8 |
No screenshot while the load average per core is higher |