Skip to content

feat: optional idle auto-close for unused browser#223

Open
7sorium wants to merge 1 commit into
executeautomation:mainfrom
7sorium:feat/optional-idle-timeout
Open

feat: optional idle auto-close for unused browser#223
7sorium wants to merge 1 commit into
executeautomation:mainfrom
7sorium:feat/optional-idle-timeout

Conversation

@7sorium

@7sorium 7sorium commented May 31, 2026

Copy link
Copy Markdown

Motivation

When a session keeps the MCP server alive but stops using the browser, the launched Chromium stays open indefinitely — there's currently no inactivity timeout. Across many long-lived sessions these idle headless browsers accumulate and consume significant memory.

What this adds

An opt-in, off-by-default idle auto-close:

  • Enabled only when the PLAYWRIGHT_IDLE_TIMEOUT_MS environment variable is set to a positive number of milliseconds (e.g. 1800000 = 30 min).
  • The timer resets on every browser tool call, so an actively-used browser is never closed.
  • The timer is cleared when the browser closes or disconnects.
  • When it fires, the browser is closed; the next browser tool call re-launches lazily (existing behavior).
  • The timer is unref()'d so it never keeps the process alive on its own.

No behavior change unless configured — with the variable unset, getIdleTimeoutMs() returns 0 and the timer never arms.

Verification

  • PLAYWRIGHT_IDLE_TIMEOUT_MS=3000: a browser left idle is closed automatically ([Playwright MCP] Closing idle browser after 3000ms of inactivity) while the server stays alive.
  • Variable unset: the browser stays open indefinitely.
  • All 150 existing tests pass; build is clean.

Notes

Pairs naturally with #222 (orphan cleanup on disconnect) but is fully independent and can be merged on its own, in any order.

🤖 Generated with Claude Code

Adds an opt-in idle timeout that closes the browser after a period of
inactivity, so long-lived sessions don't accumulate stale headless
browsers eating memory. Disabled by default — enabled only when the
PLAYWRIGHT_IDLE_TIMEOUT_MS environment variable is set to a positive
number of milliseconds. The timer resets on every browser tool call and
is cleared when the browser closes or disconnects. No behavior change
unless explicitly configured.

Verified: with PLAYWRIGHT_IDLE_TIMEOUT_MS=3000 a browser left idle is
closed automatically while the server stays alive; with the variable
unset the browser stays open.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant