#42962·Playwright

[Bug]: default font families are lost after any screenshot captured beyond the viewport (Chromium headless shell)

Author: TheMalloumCreated Sep 28, 2026Updated Sep 28, 2026

Version

1.63.0 (bundled Chromium headless shell 153.0.8010.12)

Steps to reproduce

javascript
const { chromium } = require('playwright');

const lines = Array.from({ length: 40 }, (_, i) => `<p>The quick brown fox ${i}</p>`).join('');
const html = family => `<body style="margin:0;font:22px ${family}"><h1>Title</h1>${lines}<p id="last">last</p>`;

async function probe(page) {
  const cdp = await page.context().newCDPSession(page);
  await cdp.send('DOM.enable');
  await cdp.send('CSS.enable');
  const { root } = await cdp.send('DOM.getDocument');
  const { nodeId } = await cdp.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'h1' });
  const { fonts } = await cdp.send('CSS.getPlatformFontsForNode', { nodeId });
  await cdp.detach();
  const y = await page.evaluate(() => Math.round(document.querySelector('#last').getBoundingClientRect().top));
  return `${fonts[0].postScriptName} (last line at ${y}px)`;
}

(async () => {
  const browser = await chromium.launch();
  console.log(process.platform, browser.version());
  for (const family of ['sans-serif', 'serif', 'monospace', 'cursive', 'fantasy']) {
    const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
    await page.setContent(html(family));
    console.log(`\n${family}`);
    console.log('  initial:', await probe(page));
    await page.screenshot();
    console.log('  after page.screenshot():      ', await probe(page));
    await page.screenshot({ fullPage: true });
    console.log('  after screenshot({fullPage}): ', await probe(page));
    await page.goto('data:text/html,' + encodeURIComponent(html(family)));
    console.log('  after goto:                   ', await probe(page));
    await page.close();
  }
  await browser.close();
})();

Expected behavior

The font resolved for a generic family (sans-serif, serif, monospace, cursive, fantasy) stays the one Playwright sets with Page.setFontFamilies (defaultFontFamilies.ts) for the whole life of the page. Taking a screenshot does not lay the page out again.

Actual behavior

After the first screenshot captured beyond the viewport, the generic families resolve to other fonts and the page is laid out again. A viewport-only screenshot does not do it. A navigation brings Playwright's families back, and the next such screenshot drops them again.

macOS, arm64:

sans-serif
 initial: Helvetica-Bold (last line at 1960px)
 after page.screenshot(): Helvetica-Bold (last line at 1960px)
 after screenshot({fullPage}): Arial-BoldMT (last line at 1999px)
 after goto: Helvetica-Bold (last line at 1960px)
serif: Times-Bold -> TimesNewRomanPS-BoldMT
monospace: Courier-Bold -> Menlo-Bold
cursive: Apple-Chancery (2378px) -> TimesNewRomanPS-BoldMT (2000px)
fantasy: Papyrus (2337px) -> Impact (2042px)

Linux (Ubuntu 24.04 in Docker, arm64): only monospace changes, the family where Playwright's default (Monospace) and Chromium's differ.

monospace: WenQuanYiZenHeiMono (2168px) -> LiberationMono-Bold (1959px)

Additional context

Same root cause as #42607, for another setting.

Page.captureScreenshot with captureBeyondViewport: true pushes WebPreferences twice (page_handler.cc). WebView::ApplyWebPreferences applies every font family map of those preferences (web_view_impl.cc, ApplyFontsFromMap), in the same function that sets max_touch_points. The families set through Page.setFontFamilies at page initialization (_setDefaultFontFamilies, headless only) are overwritten.

The trigger is captureBeyondViewport alone. Over raw CDP, on the same page:

  • Page.captureScreenshot with a 1x1 clip and captureBeyondViewport: true changes the fonts;
  • the same command without captureBeyondViewport does not;
  • resizing the viewport and restoring it, without any screenshot, does not.

It does not reproduce with channel: 'chromium' on macOS, except for monospace (Courier -> Menlo, same metrics).

#42617 re-sends Emulation.setTouchEmulationEnabled after such a capture; the font families are not re-sent.

Likely related: #29968, #11177.

Environment

bash
System:
  OS: macOS
  CPU: arm64
Binaries:
  Node: 22.17.0
npmPackages:
  playwright: 1.63.0