Skip to content

feat(mcp): add --timeout-idle to close the browser after inactivity - #42663

Merged
Yury Semikhatsky (yury-s) merged 2 commits into
microsoft:mainfrom
yury-s:fix-42548
Sep 10, 2026
Merged

Yury Semikhatsky (yury-s) merged 2 commits into
microsoft:mainfrom
yury-s:fix-42548

Conversation

@yury-s

@yury-s Yury Semikhatsky (yury-s) commented Sep 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds an opt-in --timeout-idle <ms> option (config timeouts.idle, env PLAYWRIGHT_MCP_TIMEOUT_IDLE) that closes the browser after that long without a tool call and relaunches it on the next one, prepending a note so the agent navigates again.
  • With --shared-browser-context one timer spans all clients: an idle client keeps its state while others work, and the shared browser closes once every client has been idle for the timeout.
  • Browsers attached over --cdp-endpoint or --extension are only disconnected from, and the note says to check the open tabs instead.

Fixes #42548

The browser is launched by the first tool call and kept until the server
exits, so an animating page burns CPU for the whole agent session. With
--timeout-idle the browser is closed after that long without a completed
tool call and relaunched on the next one, which is told what happened.

With a shared browser context the timer spans all clients: an idle client
keeps its tabs and state while others work, and the browser is closed once
every client has been idle. Browsers attached over CDP or the extension are
only disconnected from, since their pages live on.

Fixes: microsoft#42548

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

The config test already covers the option being off by default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@yury-s
Yury Semikhatsky (yury-s) merged commit 9e371c0 into microsoft:main Sep 10, 2026
15 of 17 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

11 failed
❌ [firefox] › mcp/annotate.spec.ts:386 › should cancel browser_annotate when the MCP request is aborted @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-core.spec.ts:106 › fill numeric @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-keyboard.spec.ts:19 › press @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-parsing.spec.ts:76 › negative number arguments @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-session.spec.ts:164 › workspace isolation - sessions in different workspaces are isolated @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-session.spec.ts:196 › list --all lists sessions from all workspaces @mcp-windows-latest-firefox
❌ [firefox] › mcp/dashboard.spec.ts:108 › should activate session when show is called with -s @mcp-windows-latest-firefox
❌ [firefox] › mcp/http.spec.ts:105 › http transport browser lifecycle (isolated) @mcp-windows-latest-firefox
❌ [firefox] › mcp/http.spec.ts:145 › http transport browser sigint @mcp-windows-latest-firefox
❌ [webkit] › mcp/http.spec.ts:105 › http transport browser lifecycle (isolated) @mcp-windows-latest-webkit
❌ [webkit] › mcp/http.spec.ts:145 › http transport browser sigint @mcp-windows-latest-webkit

8425 passed, 1392 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

🟢 The failing CI is pre-existing MCP flakiness, not this PR

Hi, I'm the Playwright bot and I took a first look at the red CI here.

All 11 failures are known flaky MCP tests, mostly on the mcp-windows-latest-firefox bot, and every one of them fails on unrelated SHAs across the results DB. An earlier run of this same PR (run 34531606415) went fully green, then the rerun (run 34539238469) tripped these. The diff touches the MCP idle-timeout feature and http.spec.ts, but the two http tests that failed flake on bots and OSes this PR never touched. Nothing here looks caused by the change.

Details

Overall assessment: the PR is clear. Nine of the failures are mcp-windows-latest-firefox-only, a bot that flakes across nearly every MCP spec. The two http.spec.ts cases are cross-bot flakes with long histories on Ubuntu/webkit/chromium where this PR has no bearing. Failure counts below are from the aggregated CI results DB (~700 runs/bot).

Pre-existing flake / infra

  • [firefox] › mcp/http.spec.ts:105 › http transport browser lifecycle (isolated) and [webkit] › :105 (same on windows-firefox/webkit) — flakes everywhere, not just here: ubuntu-chromium 17/711, ubuntu-firefox 14/701, ubuntu-webkit 11/713, plus windows-firefox/webkit/msedge. Cross-OS, cross-engine, on SHAs unrelated to this PR.
  • [firefox] › mcp/http.spec.ts:145 › http transport browser sigint and [webkit] › :145 — same story: windows-firefox 7, windows-webkit 5, windows-chromium 4, msedge 2, ubuntu-firefox 1, over hundreds of runs.
  • [firefox] › mcp/annotate.spec.ts:386 › should cancel browser_annotate when the MCP request is aborted — flaky on windows-firefox 16/696, and on windows-chrome/chromium/msedge too.
  • [firefox] › mcp/cli-core.spec.ts:106 › fill numeric — windows-firefox 6/696 (also macos-chromium once).
  • [firefox] › mcp/cli-keyboard.spec.ts:19 › press — windows-firefox 8/696.
  • [firefox] › mcp/cli-parsing.spec.ts:76 › negative number arguments — windows-firefox 11/345, plus webkit on ubuntu/macos/windows.
  • [firefox] › mcp/cli-session.spec.ts:164 › workspace isolation - sessions in different workspaces are isolated — windows-firefox 4/696 (also macos-chrome).
  • [firefox] › mcp/cli-session.spec.ts:196 › list --all lists sessions from all workspaces — windows-firefox 4/696.
  • [firefox] › mcp/dashboard.spec.ts:108 › should activate session when show is called with -s — windows-firefox 4/696.

The mcp-windows-latest-firefox bot is the common thread: it flakes across annotate, cli-*, dashboard, and http specs regardless of the change under test.

Caused by this PR

  • None found.

Uncertain

  • None.

Triaged by the Playwright bot - agent run

Yury Semikhatsky (yury-s) added a commit to microsoft/playwright-mcp that referenced this pull request Sep 14, 2026
## What's New

### 🎉 New Tools

- **`browser_webmcp_list` / `browser_webmcp_call`** — List and call the
tools a page registers through the
[WebMCP](https://webmachinelearning.github.io/webmcp/) API, letting the
page do the work instead of driving its UI. When a page has WebMCP
tools, the page status reports how many are available
([#42613](microsoft/playwright#42613)). WebMCP
is experimental, see [WebMCP in
Chrome](https://developer.chrome.com/docs/ai/webmcp) for how to enable
it.

### Other Changes

- New `--profile-dir-name <name>` option (env
`PLAYWRIGHT_MCP_PROFILE_DIR_NAME`) selects the Chrome profile to connect
to in extension mode when the extension is installed in several
profiles, for example `"Profile 1"`
([#42527](microsoft/playwright#42527))
- Headless browsers launched by the server are now closed after one hour
without tool calls; the next tool call launches a new one. Use
`--idle-timeout <ms>` (config `timeouts.idle`, env
`PLAYWRIGHT_MCP_IDLE_TIMEOUT`) to change the timeout, `0` disables it.
Headed and attached browsers are not closed unless a timeout is set
explicitly
([#42663](microsoft/playwright#42663),
[#42676](microsoft/playwright#42676))
- `--image-responses` accepts `only`: a response that carries an image
consists of the image parts alone, without the text part
([#42672](microsoft/playwright#42672))

## Bug Fixes

- `browser_close` returns an error when the browser context is shared
(`--shared-browser-context`) instead of breaking the calling client's
session. This supersedes the v0.0.80 change that dropped the backend
after `browser_close`
([#42495](microsoft/playwright#42495))
- With `--shared-browser-context`, `browser_start_recording` /
`browser_stop_recording` (opt-in via `--caps=devtools`) keep each
client's recording separate instead of delivering one client's recorded
actions to another
([#42622](microsoft/playwright#42622),
[#42627](microsoft/playwright#42627))
- The file access check follows symlinks, so a symlink inside the
workspace can no longer be used to read or write files outside the
allowed roots
([#42628](microsoft/playwright#42628))
- Explicitly named output files in a nested directory (e.g.
`sub/shot.png`) no longer fail with `ENOENT`; `browser_file_upload` and
`browser_drop` resolve relative paths against the workspace root
([#42540](microsoft/playwright#42540))
- In extension mode with `PLAYWRIGHT_MCP_EXTENSION_TOKEN` set, a
connection that never completes (e.g. the token belongs to another
Chrome profile) now fails after 30 seconds with a hint instead of
hanging the tool call forever
([#42525](microsoft/playwright#42525))
- Disable the Chromium sandbox by default on Linux for the bundled
Chromium build, which lacks the setuid sandbox helper
([#42490](microsoft/playwright#42490))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MCP]: option to close the browser after an idle period

2 participants