Tools & IDEs Bug Report

Headless Chrome screenshots show empty boxes instead of CJK text and emoji

Social preview images rendered fine on laptops but showed rows of empty boxes for Japanese, Vietnamese accents and emoji in production. The slim container image had almost no fonts, so fontconfig had nothing to fall back to.

Nadia Haddad Nadia Haddad @nadiahaddad · November 19, 2026 · 7 min read · 169 Views
591-headless-screenshots-missing-fonts-emoji-tofu

We generate Open Graph preview images for user posts with headless Chrome: an HTML template, a screenshot, upload. After moving the generator into a new slim container image, support received reports that previews for some posts showed rows of small empty rectangles. Every affected post contained Japanese or Chinese text, emoji, or in one case Vietnamese with stacked diacritics. English-only posts looked perfect.

The empty rectangles, often called "tofu", are what the renderer draws when no installed font has a glyph for a character. There was no error anywhere: Chrome rendered successfully and returned a valid PNG.

Reproducing it

A one-line page is enough (emoji and Vietnamese letters written as HTML character references so the snippet survives any editor):

docker run --rm -v "$PWD:/out" og-renderer:2026.12 node -e '
  const p = require("puppeteer");
  (async () => {
    const b = await p.launch();
    const pg = await b.newPage();
    await pg.setContent("<p style=\"font-size:48px\">Hello 日本語 中文 Ti&#x1EBF;ng Vi&#x1EC7;t &#x1F680;</p>");
    await pg.screenshot({ path: "/out/tofu.png" });
    await b.close();
  })();'

In the output, the Latin text rendered, the CJK characters and the emoji were boxes, and the Vietnamese characters rendered but in a different font from the Latin text.

What we ruled out

  • Encoding. The HTML was UTF-8 with the right meta tag, and document.body.innerText returned the correct characters. The text was intact; only drawing failed.

  • The web font. Our template uses a Latin web font loaded with @font-face. It never included CJK or emoji, and on laptops those characters came from system fonts.

  • Chrome version. Same Chrome for Testing build as before the image change.

Root cause

We checked which fonts the container had:

docker run --rm og-renderer:2026.12 fc-list
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold

The old image was based on a full Debian image with many font packages pulled in by other tools. The new one was based on node:22-bookworm-slim, where only DejaVu came in as a dependency of Chrome's libraries. DejaVu covers Latin, Greek, Cyrillic and Vietnamese, but has no CJK glyphs and no colour emoji. On Linux, Chrome asks fontconfig for a fallback font for each missing character; with no font covering the character, it draws a box.

docker run --rm og-renderer:2026.12 fc-match ':lang=ja'
DejaVuSans.ttf: "DejaVu Sans" "Book"

fontconfig returns DejaVu as the closest match for Japanese, even though it cannot draw a single Japanese glyph.

What is happening under the hood

When the text uses font-family: "Brand Sans", sans-serif, Chrome first tries the web font, then the generic sans-serif mapping, then per-character fallback. On Linux, the generic families and fallback both come from fontconfig, which reads font files from directories such as /usr/share/fonts and its cache in /var/cache/fontconfig.

Desktop Linux distributions install dozens of font packages, so fallback almost always finds something. Minimal container images install only what packages strictly depend on. That makes "works on my machine" particularly likely: macOS and Windows ship broad CJK and emoji fonts, so the problem never appears locally.

Emoji are a separate case. They need a colour emoji font; on Linux the standard choice is Noto Color Emoji. Without it, emoji either render as boxes or, if some font has a monochrome glyph, in black and white.

Environment

Component

Version / value

Base image

node:22-bookworm-slim (Debian 12)

Node.js

22 LTS

Puppeteer

24.x with bundled Chrome for Testing

Fonts installed

DejaVu only (fonts-dejavu-core)

Template font

Latin web font via @font-face, fallback sans-serif

Minimal reproduction

<!doctype html>
<meta charset="utf-8">
<style>body { font: 48px "Brand Sans", sans-serif; }</style>
<p>日本語 · 中文 · 한국어 · &#x1F680;&#x1F389; · Ti&#x1EBF;ng Vi&#x1EC7;t</p>

Who is affected

Any headless browser on Linux with a minimal font set: Puppeteer, Playwright and Selenium in slim or Alpine images, serverless runtimes, and CI runners. PDF generation is affected the same way as screenshots, and in PDFs the boxes are embedded permanently.

Install fonts that cover your users' scripts

For Debian and Ubuntu based images:

RUN apt-get update && apt-get install -y --no-install-recommends \
      fontconfig \
      fonts-noto-core \
      fonts-noto-cjk \
      fonts-noto-color-emoji \
      fonts-liberation \
 && fc-cache -f \
 && rm -rf /var/lib/apt/lists/*
  • fonts-noto-core covers most living scripts.

  • fonts-noto-cjk covers Chinese, Japanese and Korean. It is large (well over 100 MB installed), so check whether you need it before adding it to small images.

  • fonts-noto-color-emoji provides colour emoji.

  • fonts-liberation provides metric-compatible replacements for Arial, Times New Roman and Courier New, which keeps layout stable for templates that name those fonts.

For Alpine based images, the equivalent packages are font-noto, font-noto-cjk and font-noto-emoji, followed by fc-cache -f.

Playwright users can run npx playwright install-deps chromium, which installs the system libraries and a basic set of fonts. Check whether that set covers your scripts; we still added CJK and emoji explicitly.

Rebuild the font cache and restart the browser

fontconfig reads its cache when the browser starts. Fonts installed into a running container, or copied into a directory without running fc-cache, are not picked up until the cache is rebuilt and Chrome is relaunched. Install fonts at image build time, not at runtime.

Bundle the template's fonts

For branded images, system fonts are a fallback, not the design. We now self-host the fonts the template uses and wait for them before the screenshot:

await page.setContent(html, { waitUntil: 'load' });
await page.evaluate(() => document.fonts.ready);
await page.screenshot({ path: outFile });

document.fonts.ready resolves once font loading in the document is finished, so the first screenshot never shows a fallback font that swaps in a moment later.

Alternatives and trade-offs

  • Ship only the scripts you need. Image size matters for cold starts. If you only serve Latin and Vietnamese, fonts-noto-core is enough. Our users post in Japanese, so CJK stayed.

  • Use web fonts for everything. Loading a full CJK web font per render is slow unless you subset it. System fonts in the image were simpler.

How to test the fix

Rebuild the image and check coverage per language:

docker run --rm og-renderer:2026.12 sh -c '
  fc-match ":lang=ja"; fc-match ":lang=zh-cn"; fc-match ":lang=ko"; fc-match emoji'
NotoSansCJK-Regular.ttc: "Noto Sans CJK JP" "Regular"
NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"
NotoSansCJK-Regular.ttc: "Noto Sans CJK KR" "Regular"
NotoColorEmoji.ttf: "Noto Color Emoji" "Regular"

Then rerun the one-line reproduction and confirm the screenshot shows every character.

Confirming in production

  • We regenerated preview images for the 2,300 posts created during the affected period and spot-checked 100 across languages.

  • The image grew by about 160 MB. Cold start for the renderer increased by under a second, which was acceptable for a queue worker.

Regression guard

We added a visual test that renders a fixed "glyph coverage" page with Latin, Vietnamese, Japanese, Chinese, Korean, Arabic and emoji samples inside the production image, and compares it with a reviewed baseline. A font package removed from the Dockerfile now fails CI.

We also run a quick check at container startup that logs the result of fc-match for each language we support, which makes a broken image obvious in the first log lines.

Security implications

None beyond normal supply chain hygiene: install fonts from the distribution's signed repositories, not by downloading font files from arbitrary URLs during the build. Font files are parsed by the renderer, so untrusted fonts are an attack surface; keep the browser updated and avoid letting users upload fonts into the renderer.

Prevention checklist

  • Decide which scripts and emoji your renders must support and install matching fonts in the image.

  • Run fc-cache -f at build time and never install fonts into running containers.

  • Self-host template fonts and wait for document.fonts.ready before capturing.

  • Keep a glyph coverage page in your visual test suite, rendered in the production image.

  • Log fc-match results per language at startup.

References

Add a label

#docker #fonts #headless-chrome #puppeteer #fontconfig
Written by
Nadia Haddad @nadiahaddad

I moved into security from software development, and I still think like a developer: what does this mean for the code I am about to merge? Today I run security training and help engineering teams build safer systems without slowing them down. This series is the course I wish I had been given early in my career. It covers the fundamentals, from the CIA triad and networking basics to cryptography and access control, explained for developers with concrete examples and no fear-mongering. Every topic ends with something you can check or change in your own systems this week.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.