Repository navigation
Description
Version
1.61.0-next (reproduces on 1.58.x and older chromium-headless-shell r1147 / Chromium 131 too — not a recent regression)
Steps to reproduce
Related: #39335 (original report) and #38776 (previous fix attempt, reverted by #39994 because it broke Inspector / codegen / UI mode in #39990).
Minimal reproduction (single file):
// repro.js
const { spawn } = require('child_process');
const inner = `
const { chromium } = require('playwright');
(async () => {
const b = await chromium.launch({ headless: true });
await new Promise(r => setTimeout(r, 10000));
await b.close();
})();
`;
// Outer parent with { detached: true, stdio: 'ignore' } — the pattern used by
// Playwright's CLI dashboard daemon, session daemon, and MCP annotate daemon.
const p = spawn(process.execPath, ['-e', inner], { detached: true, stdio: 'ignore' });
p.unref();Run node repro.js on Windows. A black console window appears for ~10s, titled with the full path of chrome-headless-shell.exe.
In real usage this fires whenever Playwright internals spawn a detached helper (e.g. playwright cli show, MCP dashboard/annotate daemons, session open) that later launches a headless browser.
Expected behavior
No visible console window — the browser is headless.
Actual behavior
A black cmd window appears for the lifetime of the browser. Title is the full path of chrome-headless-shell.exe, window class is ConsoleWindowClass, size ~912×517. Matches the screenshot in #39335.
Why this happens (PE subsystem analysis)
Every Windows PE executable has a subsystem flag. When CreateProcessW creates a process for a console-subsystem binary without CREATE_NO_WINDOW, Windows allocates a conhost window. For GUI-subsystem binaries, it does not.
Of the browsers Playwright spawns, only chrome-headless-shell.exe is linked as WINDOWS_CUI (console):
| Binary | PE subsystem | Allocates console on spawn? |
|---|---|---|
chrome-headless-shell.exe |
WINDOWS_CUI (3) |
yes |
chrome.exe (Chrome for Testing) |
WINDOWS_GUI (2) |
no |
msedge.exe |
WINDOWS_GUI (2) |
no |
firefox.exe |
WINDOWS_GUI (2) |
no |
Node's default for child_process.spawn on Windows does not pass CREATE_NO_WINDOW unless windowsHide: true is set. Normally, a piped stdio means the child inherits the parent's (non-visible) console, so no new window appears. But when the outer parent is spawned with detached: true and stdio: 'ignore', Windows gives the new process group a brand-new console — and when that parent later launches chrome-headless-shell.exe via Playwright's launchProcess, the inherited console becomes visible.
That's why the bug only manifests when there's a detached intermediate (CLI daemon / MCP dashboard daemon / session open). A plain chromium.launch({ headless: true }) from a normal Node process doesn't show the window because the parent's already-hidden console is inherited.
Confirmed not a recent regression: reproduces on chromium-headless-shell r1147 (Nov 2024, Chromium 131) as well as current r1224. Playwright's processLauncher.ts has been functionally stable for years.
Also verified that full chrome.exe --headless=new (via executablePath + args: ['--headless=new']) does not reproduce — because the full Chromium binary is GUI-subsystem.
Proposed fix
Inside packages/utils/processLauncher.ts (launchProcess), set windowsHide: true iff the launched binary is a console-subsystem PE. This is automatic, doesn't depend on filename matching, and leaves GUI-subsystem binaries (full chromium.exe, firefox.exe, msedge.exe, Inspector headful Chromium) untouched — so it doesn't regress #39990.
// On Windows, hide the console that the OS allocates for console-subsystem (WINDOWS_CUI)
// binaries like chrome-headless-shell.exe. GUI-subsystem binaries are unaffected.
let windowsHide = false;
if (process.platform === 'win32' && !options.shell) {
try {
const fd = fs.openSync(options.command, 'r');
try {
const header = Buffer.alloc(0x100);
fs.readSync(fd, header, 0, 0x100, 0);
const peOffset = header.readUInt32LE(0x3C);
const tail = Buffer.alloc(0x80);
fs.readSync(fd, tail, 0, 0x80, peOffset);
// PE sig (4) + COFF header (20) + OptionalHeader.Subsystem offset 68
windowsHide = tail.readUInt16LE(4 + 20 + 68) === 3; // IMAGE_SUBSYSTEM_WINDOWS_CUI
} finally { fs.closeSync(fd); }
} catch {}
}
const spawnOptions = { detached: process.platform !== 'win32', windowsHide, /* … */ };Tested with the patch applied to packages/playwright-core/lib/coreBundle.js:
- Repro above: 0 visible console windows across 3 runs (before: 1+ per run).
npx playwright codegen https://example.com: Inspector window appears correctly (titled "Playwright Inspector - https://example.com/") alongside the browser — no Inspector regression.
Simpler alternative if a PE read feels too fancy: basename-match options.command against /chrome-headless-shell/i at the spawn site. Semantically less principled but equivalent in practice since no other binary Playwright spawns is console-subsystem.
Debugging helpers used
Check PE subsystem of any binary (PowerShell):
function Get-Subsystem {
param($Path)
$b = [IO.File]::ReadAllBytes($Path)
$peOffset = [BitConverter]::ToInt32($b, 0x3C)
$subsys = $peOffset + 4 + 20 + 68
switch ([BitConverter]::ToUInt16($b, $subsys)) {
2 { 'WINDOWS_GUI' } 3 { 'WINDOWS_CUI (Console)' } default { "Subsystem=$_" }
}
}Window watcher (polls 10 ms for new visible ConsoleWindowClass windows; logs PID + command line):
Add-Type @'
using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text;
public class Win {
public delegate bool EWP(IntPtr h, IntPtr l);
[DllImport("user32.dll")] public static extern bool EnumWindows(EWP f, IntPtr l);
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint p);
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetClassName(IntPtr h, StringBuilder s, int c);
}
'@
$seen = @{}
while ($true) {
[Win]::EnumWindows({ param($h, $l)
if (-not [Win]::IsWindowVisible($h)) { return $true }
$cls = New-Object Text.StringBuilder 256
[Win]::GetClassName($h, $cls, 256) | Out-Null
if ($cls.ToString() -ne 'ConsoleWindowClass') { return $true }
if ($seen.ContainsKey([long]$h)) { return $true }
$seen[[long]$h] = $true
[uint32]$pid = 0
[Win]::GetWindowThreadProcessId($h, [ref]$pid) | Out-Null
$cim = Get-CimInstance Win32_Process -Filter ("ProcessId=" + $pid)
Write-Host "HIT pid=$pid cmd=$($cim.CommandLine)"
return $true
}, [IntPtr]::Zero) | Out-Null
Start-Sleep -Milliseconds 10
}Sample output during reproduction:
HIT pid=5752 cmd=C:\Users\…\chrome-headless-shell-win64\chrome-headless-shell.exe --headless --no-sandbox … --remote-debugging-pipe --no-startup-window
Additional context
Same underlying bug as #39335. PR #38776 attempted to fix it by adding windowsHide: true unconditionally to packages/utils/processLauncher.ts (the sole child_process.spawn that launches every browser). It was reverted by #39994 because the same flag also suppressed the headful Chromium window used for the Inspector / codegen / UI mode (#39990 — Inspector launched via launchApp at packages/playwright-core/src/server/recorder/recorderApp.ts:210-216, using full chromium.exe with headless: false).
The PE-subsystem approach above avoids that, because the Inspector's binary (chrome.exe) is WINDOWS_GUI and windowsHide: true is never applied to it.
Environment
System:
OS: Windows 11 10.0.26100
CPU: (12) x64 AMD Ryzen 5 PRO 230 w/ Radeon 760M Graphics
Binaries:
Node: 24.14.1
npm: 11.11.0
npmPackages:
@playwright/test: 1.61.0-next (reproduces on older versions too)
Activity
mxschmitt commentedon May 8, 2026
Closing for now since I'm not blocked by it, only filed it for completeness.
fix(browse): use full-Chromium new headless on Windows to stop consol…