#292·pretext

Emoji width correction doesn't run inside Web Workers

Author: chenglouCreated Sep 15, 2026Updated Sep 15, 2026

On macOS, Chrome's and Firefox's canvas measureText() reports Apple Color Emoji wider than the page paints it at small font sizes (see PLATFORM_BUGS.md). Pretext works around this once per font in getEmojiCorrection() (src/measurement.ts): it measures on canvas, and if that looks too wide, it measures a hidden span in document.body and subtracts the difference for every emoji.

A Web Worker has no document, so the correction silently stays 0 there. Text with emoji prepared in a worker would measure wider than what the page paints, so a worker computing heights could count more lines than the main thread draws. Without the correction our accuracy sweeps drop from 7680/7680 to 7660 in Chrome and 7652 in Firefox. I haven't checked that OffscreenCanvas inside a worker reports the same emoji widths as the page's canvas, but I'd expect it to.

This came up while thinking about laying out a very long chat on workers. One way out is to let the page read its correction for a font and hand it to the worker. Related: #34, and the ENGINE_FOLLOWUPS.md note that no canvas follows a worker's lang.