Stabilize text rendering
Disable subpixel text and font hinting in headless Chromium to reduce glyph rendering differences between machines.
Reduce glyph rendering differences between machines: disable subpixel (LCD) text and font hinting in headless Chromium. This removes one of the most common sources of screenshot noise. It does not make macOS and Linux render text identically, so capture your screenshots in a single environment, usually CI.
Why text causes flaky screenshots
By default, Chromium renders text using two techniques that depend on the underlying operating system, GPU, and font stack:
Subpixel (LCD) antialiasing uses the red, green, and blue subpixels of a screen to smooth glyph edges. It leaves faint red/blue color fringing that differs from one machine to another.
Font hinting snaps glyphs to the pixel grid. The result varies between platforms, shifting antialiasing by a pixel here and there.
The consequence: a screenshot captured locally on macOS rarely matches the exact same screenshot captured on a Linux CI runner. Argos sees these sub-pixel differences as real changes and reports false positives, even though no code changed.
The fix
Launch Chromium with two flags that remove the most variable parts of text rendering:
--disable-lcd-text— forces grayscale antialiasing instead of subpixel rendering, removing the red/blue edge fringing.--font-render-hinting=none— disables font hinting, so glyphs are no longer snapped to each platform's pixel grid. Chromium only reads this flag in headless mode (the headless shell Playwright uses by default); it has no effect on a headed browser.
Add the launch options to the use block of your Playwright configuration:
import { defineConfig } from "@playwright/test";
export default defineConfig({
use: {
launchOptions: {
args: ["--disable-lcd-text", "--font-render-hinting=none"],
},
},
});Pass the launch options to the Playwright provider in your Vitest configuration:
import { defineConfig } from "vitest/config";
import { playwright } from "@vitest/browser-playwright";
export default defineConfig({
test: {
browser: {
enabled: true,
provider: playwright({
launchOptions: {
args: ["--disable-lcd-text", "--font-render-hinting=none"],
},
}),
instances: [{ browser: "chromium" }],
},
},
});Last updated
Was this helpful?