#42960·Playwright

[MCP]: browser_wait_for per-call timeout for text / textGone

Author: tugkanbozCreated Sep 28, 2026Updated Sep 28, 2026

What's going on?

Problem

browser_wait_for with text or textGone waits using the action timeout (tab.actionTimeoutOptions, 5000 ms by default). There is no way to extend it per call, while a fixed time wait is allowed up to 30 s.

As a result, "wait until this text appears" fails after 5 s on slow-loading pages:

### Error
TimeoutError: Timeout 5000ms exceeded.
Call log:
  - waiting for getByText('Loading complete').first() to be visible

Why it matters

On a module-federation SPA whose app shell renders 10–50 s after navigation, browser_wait_for gives up before the page is ready. The agent then falls back to writing its own polling inside browser_evaluate:

javascript
for (let i = 0; i < 20; i++) { await sleep(1000); if (document.querySelector(...)) break; }
await sleep(3000);

Across several sessions, ~47% of the time spent in Playwright tools went into evaluate / run_code polling loops like this, with single calls taking 100–150 s. These loops keep sleeping after the element has appeared, and nothing meaningful ends up in the generated code.

The only workaround today is raising --timeout-action, which also slows down every click / type / hover call on a missing element.

Proposal

Add an optional timeout parameter (in seconds) to browser_wait_for:

  • It applies only to the text / textGone waits.
  • It is capped at maxWaitSeconds (30 s), consistent with time.
  • When omitted, the current behavior (action timeout) is unchanged.
typescript
timeout: z.number().optional().describe(`Maximum time to wait for text/textGone in seconds, at most ${maxWaitSeconds}. Defaults to the action timeout.`),

The change would be contained in packages/playwright-core/src/tools/backend/wait.ts, plus a test.

Version

No response