Repository navigation
Description
What's going on?
Measured on Windows 11 only. Not tested on macOS or Linux.
When the client closes the stdio server's stdin, two shutdown paths fire:
process.stdin.on('end', () => void transport.close())in packages/playwright-core/src/tools/utils/mcp/server.ts (line 193 on main), which closes the browser through the normal close.- The exit watchdog,
process.stdin.on('close', () => handleExit('close'))in packages/playwright-core/src/tools/mcp/watchdog.ts (line 35 on main), which callsgracefullyCloseAll().
As far as I can read, both reach gracefullyClose() of the same launched browser in packages/utils/processLauncher.ts. The first call sets gracefullyClosing. The second finds it set and takes the force branch (lines 215-219 on main): <forcefully close>, then killProcess(), which on Windows is killProcessTree(), that is taskkill /pid <browser pid> /T /F started through a shell (line 275 on main).
Playwright's own log with DEBUG=pw:browser* shows that. Chromium and Firefox gave the same sequence (2 of 2 runs):
<gracefully close start>
<forcefully close> 1 ms later
<kill>
<will force kill>
<process did exit: exitCode=0, signal=null> about 640 ms (Chromium) and 690 ms (Firefox) after the start
<gracefully close end>
Tracing the server's child processes: in 8 of 8 runs the server started cmd.exe, which started taskkill.exe, 76 to 106 ms after its stdin was closed.
A persistent profile can lose its latest writes if taskkill lands before the browser's own shutdown has written its stores. Setup: persistent userDataDir; a page writes one persistent cookie (max-age set) and 40 localStorage keys; 1 s later the client closes stdin and the server exits on its own; the same profile is then relaunched and read back.
- 10 of 12 runs kept everything.
- 1 of 5 Chromium runs lost the cookie.
- 1 of 7 Firefox runs lost every localStorage key; the origin's ls/data.sqlite was left at 0 bytes.
Calling browser_close before closing stdin kept everything in 6 of 6 runs (3 Chromium, 3 Firefox), even with the whole process tree killed the moment the tool answered (203 to 286 ms for Chromium, 533 to 592 ms for Firefox).
Steps to reproduce (Windows):
- Start the server with a persistent profile, for example a config like
and DEBUG=pw:browser* in its environment.
{"browser": {"browserName": "chromium", "userDataDir": "<an empty folder>", "launchOptions": {"channel": "chrome-for-testing", "headless": true}}} - Initialize, then call browser_navigate to a local page that sets a persistent cookie and some localStorage keys.
- Wait about 1 s and close the server's stdin.
- stderr shows
<gracefully close start>followed 1 ms later by<forcefully close>and<will force kill>, and the server starts cmd.exe and taskkill.exe. - Relaunch on the same profile and read the cookie and localStorage. Repeat: the loss shows up in some runs, not all. The same steps with "browserName": "firefox" show the localStorage case.
Expected: on stdin EOF the browser is closed once, gracefully, and force-killed only if that close does not finish (the watchdog already exits after 15 s, and closeOrKill already kills after 30 s).
Possible fixes, untested: let a second gracefullyClose() call wait for the first one instead of killing; or give the stdin-EOF shutdown a single owner (the transport close or the watchdog, not both).
Where the code is (read, not run, unless stated):
- playwright-core 1.64.0-alpha-1789764292000, pinned by @playwright/mcp 0.0.82 (the measured build): lib/coreBundle.js:9521-9533 (gracefullyClose), 9571-9578 (killProcessTree), 73356 (stdin end), 74118 (stdin close).
- playwright-core 1.64.0-alpha-1790635538000, pinned by @playwright/mcp 0.0.83: lib/coreBundle.js:9956-9961, 10007, 73936, 74698. Same code.
- main at c2a031e (2026-10-03): processLauncher.ts:209-221 and 272-275, watchdog.ts:35, server.ts:193. Same code.
Related, not duplicates: #41664 (the stdio server should dispose the browser when stdin closes), #41013 (orphaned Chrome trees when the host dies).
Version
@playwright/mcp 0.0.82 (playwright-core 1.64.0-alpha-1789764292000), Node v24.21.0, Windows 11. Browsers: chromium 1246 (Chrome for Testing 154.0.8037.0) and firefox 1549 (Firefox 156.0), headless.
Activity
github-actions commentedon Oct 5, 2026
Hi, I'm the Playwright bot and I took a first look on Windows.
Reproduced with the latest published
@playwright/mcp0.0.83 (playwright-core1.64.0-alpha-1790635538000). Closing the stdio client starts a graceful browser close and then re-enters the same launcher close path through the stdinclosewatchdog, which force-kills the browser. This happened with Chromium, Firefox, and WebKit, so the shutdown bug is not browser-specific. The same two stdin handlers and re-entrant force-close branch are still present on currentmainata18dade.Calling
browser_closebefore closing stdin is an effective control: Chromium then logged one graceful close and no force-kill. This looks like a real bug; #41664 and #41013 cover different lifecycle failures rather than this duplicate shutdown.Minimal repro
I started the MCP CLI with a persistent
userDataDirandDEBUG=pw:browser*, connected with the MCP SDK'sStdioClientTransport, launched the browser withbrowser_navigate, and then closed the client:The config used
browserName, a freshuserDataDir, andlaunchOptions: { headless: true }.What I ran
Windows Server 2025 Datacenter 10.0.26100, Node 24.21.0:
<forcefully close>,<will force kill><forcefully close>,<will force kill><forcefully close>,<will force kill>Chromium control with
browser_closebefore stdin EOF:I verified the deterministic double-close/force-kill sequence, but did not try to reproduce the reported probabilistic profile data loss in this pass.
Triaged on Windows by the Playwright bot - agent run
fix(mcp): close the browser once when the client disconnects
fix(mcp): do not close the browser twice when the client disconnects
fix(mcp): do not close the browser twice when the client disconnects