Repository navigation
Description
Version
1.63.0 (bundled Chromium headless shell 153.0.8010.12)
Steps to reproduce
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.captureScreenshotwith a 1x1 clip andcaptureBeyondViewport: truechanges the fonts;- the same command without
captureBeyondViewportdoes 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
System:
OS: macOS
CPU: arm64
Binaries:
Node: 22.17.0
npmPackages:
playwright: 1.63.0
Activity
donmangudata-ops commentedon Oct 6, 2026
I can reproduce this on Linux (Playwright Python 1.56.0, Chromium 141 headless shell). After
page.screenshot(full_page=True),monospaceresolves to Liberation Mono instead of DejaVu Sans Mono. A normal screenshot does not change it.A workaround that avoids
captureBeyondViewport: resize the viewport to the page height, then take a normal screenshot. In my test the fonts stayed the same, also after restoring the viewport.Resizing changes layout for
vhunits and media queries. I did not test pages that use them.Disclosure: I build commercial data tools in this area (details in my GitHub profile).
rgrzywinski commentedon Oct 9, 2026
Same on macOS arm64, Playwright 1.63.0 / Chromium headless shell 153.0.8010.12:
monospacegoesCourier-Bold→Menlo-Boldafter a beyond-viewport capture, and inlinecodelines grow 1px. Two additions:toHaveScreenshotloop on a ~30,000px page alternated heights 30049 → 30083 → 30049 across consecutive captures until it timed out on "Failed to take two consecutive stable screenshots". In isolation, the switch is one-way and stays. We can't trigger the reverse on demand.Page.setFontFamilieswith the family you want, and keep that CDP session attached for the page's life. An override sent on a session that is then detached is lost at the next navigation; one on a retained session survives it. We pin onlyfixed: 'Menlo', sent once per page before the first navigation, and all subsequent beyond-viewport captures stay byte-identical.dgozman commentedon Oct 16, 2026
Upstream issue: https://issues.chromium.org/u/1/issues/574315013
The fix should be available with the Chromium 158 roll.
pavelfeldman commentedon Oct 31, 2026
I'll close it as fixed, it should be ok in the next release.