Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Bug]: connectOverCDP({ noDefaults: true }) still overrides font families (Page.setFontFamilies) on headless browsers

Abierto
#43,715 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@microsoft-playwright-automation ya está trabajando en esto.

Desde el 29/10/2026.

  • #43773 de @microsoft-playwright-automation — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, playwright, typescript
Área
backend, testing

Línea de trabajo

Read packages/playwright-core/src/server/chromium/crPage.ts, especially FrameSession._initialize, and compare the font override call with the focus and media defaults gated by skipDefaultOverrides. Then inspect tests/library/chromium/connect-over-cdp.spec.ts for coverage of noDefaults; done means existing pages receive no font override when it is true, while default behavior remains when it is false. The issue author says they plan to work on this and a test, so check with them before starting.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage
Version

1.64.1 (reproduced on 1.63.0; the relevant code is unchanged in 1.64.1 and on main)

Steps to reproduce
  1. Start a headless Chrome with a DevTools endpoint. Any headless Chromium build should do, since the code path only depends on the user agent containing Headless:
google-chrome --headless=new --remote-debugging-port=9222 --user-data-dir=/tmp/pw-repro
  1. Save this as repro.js:
const { chromium } = require('playwright');

(async () => {
  const noDefaults = process.env.NO_DEFAULTS !== '0';
  const browser = await chromium.connectOverCDP('http://127.0.0.1:9222', { noDefaults });
  const page = await browser.contexts()[0].newPage();
  await page.goto('about:blank');
  // Leave the attached browser running: exit without browser.close().
  process.exit(0);
})();
  1. Run it with protocol logging and count which default overrides were sent:
DEBUG=pw:protocol node repro.js 2>&1 \
  | grep -oE '"method":"(Page\.setFontFamilies|Emulation\.setFocusEmulationEnabled|Emulation\.setEmulatedMedia)"' \
  | sort | uniq -c
Expected behavior

With noDefaults: true, none of Playwright's default overrides are applied to the existing default context, so the command above prints nothing. From the noDefaults docs: "When true, Playwright will not apply its default overrides to the existing default browser context."

Actual behavior

Focus emulation and media emulation are skipped as documented, but Page.setFontFamilies is still sent to every page of the default context, including tabs that were already open before connecting:

      3 "method":"Page.setFontFamilies"

This is the message that is sent:

{"method":"Page.setFontFamilies","params":{"fontFamilies":{"standard":"Times New Roman","fixed":"Monospace","serif":"Times New Roman","sansSerif":"Arial","cursive":"Comic Sans MS","fantasy":"Impact"}}}

For comparison, NO_DEFAULTS=0 sends all three, as expected.

Additional context

The font defaults are applied in FrameSession._initialize in packages/playwright-core/src/server/chromium/crPage.ts, gated only on headless mode:

if (!browserOptions.headful)
  promises.push(this._setDefaultFontFamilies(this._client));

For connectOverCDP, headful is inferred from the user agent (browser.options.headful = !version.userAgent.includes('Headless') in crBrowser.ts), so this runs for any headless target. The other two defaults next to it are gated on skipDefaultOverrides, which is why only the fonts leak through. The change that added noDefaults (#40185) gated focus and media emulation but left this call as is.

This changes how the user's existing tabs render. In a headless Chrome profile whose fonts are all set to DejaVu Sans Mono, a span of 20 i characters measures 192.7px for every generic family before connecting. Right after connectOverCDP(url, { noDefaults: true }) it measures 88.9px for the default, serif, cursive and fantasy families and 71.1px for sans-serif (numbers from my machine). The override is still in effect in those tabs after Playwright disconnects, until each tab is reloaded. Since Playwright MCP always passes noDefaults for CDP connections (#41676), --cdp-endpoint against a headless Chrome is affected as well.

Proposed fix, gating the call like the other defaults:

if (!browserOptions.headful && !skipDefaultOverrides)
  promises.push(this._setDefaultFontFamilies(this._client));

I tested this change against 1.63.0: with noDefaults: true nothing from the list above is sent and the custom fonts stay at 192.7px; with noDefaults: false the behavior is unchanged. The noDefaults docs could also mention that font families are left alone.

I would like to work on this and can send a PR with the fix and a test in tests/library/chromium/connect-over-cdp.spec.ts.

Environment
System:
  OS: Linux 7.0 Ubuntu 24.04.5 LTS
  CPU: (24) x64 Intel(R) Core(TM) Ultra 9 275HX
  Memory: 62 GB
Binaries:
  Node: 24.21.0
Browsers:
  Google Chrome: 156.0.8078.47 (--headless=new)
npmPackages:
  playwright-core: 1.63.0
Lenguaje dominante
TypeScript
Estrellas
98.5k
Forks
6.7k
Merge medio
15 h 42 min
PR fusionados (30 d)
313

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/playwright

Todos los issues de microsoft/playwright

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.