Skip to content

[Bug]: server browser actions spend more than their request's timeout; snapshot pause/resume is outside its timer #37023

Open

Description

@yaacovcorcos

Before submitting

Area

apps/server

Checked against upstream main 92595ab (2026-11-15).

Problem

An agent's browser request carries one timeoutMs, and the broker waits that long (plus a 1 s grace for
actions that update the current tab). Several operations on the server browser do not keep to that budget:

  1. Queue time is subtracted only for click. runOperation receives deadlineMs = performance.now() + request.timeoutMs
    when the request arrives, but only the click case passes the remaining time to Playwright
    (ServerBrowser.ts, case "click"). hover, drag, select, type and upload use input.timeoutMs (or the 15 s
    default), evaluate uses request.timeoutMs, and waitFor uses its input. A request that waited behind other work on
    the same tab therefore starts with its full budget again. fix(server): preview hover and drag fail within their timeout, not up to 3x later #33550 gave hover and drag one deadline across their steps,
    but that deadline still starts after queueing.

  2. select grants its budget twice. ServerBrowserPage.select passes the same timeout to locator.evaluate (reading
    the options) and then to locator.selectOption, so a slow first step leaves the second its full budget.

  3. Some steps have no limit, others the page's default. press, type's keyboard steps (select-all, delete,
    insertText) and scroll without a target (page.evaluate) take no timeout at all. scroll on a target uses
    locator.evaluate with no option, so it falls back to the page's 15 s default rather than the request's budget.

  4. Snapshot preparation and cleanup run outside the capture timer. withScreencastsPaused waits for the capture lock and
    for every viewer's pause() (an unbounded CDP Page.stopScreencast) before ServerBrowserPage.snapshot starts its 10 s
    timer, and it awaits resume() in finally after that timer. If a viewer's pause never answers, the snapshot never
    starts, the capture lock stays held, and later snapshots and recording stops on that tab queue behind it.

  5. open waits for the page's load event. A new tab with a URL awaits
    page.waitForLoadState("load", { timeout: navigationTimeout }) after its initial navigation, and an existing tab
    navigates with navigate(tab, url, "load", …); both swallow the timeout and then report the loading tab. So on a page
    whose load never fires (one image or script that never answers, long polling), opens with a URL and URL navigations
    using the default load readiness can spend their navigation budget (normally 15 s, the default and cap) waiting for
    load before they return a tab that was usable right after commit. A navigation that asks for readiness: "none" or
    "domcontentloaded", or passes a shorter timeoutMs, returns earlier.

When an operation outlives its request, the caller has already received a timeout, but the work still runs and keeps the tab's
queue (or capture lock) busy, so the next calls on that tab also time out.

#32866 (open, fixes #32849) answers each request at timeoutMs + 500 ms, refuses new actions on a tab whose started run is
overdue with a busy reason, and stops mirrorManagerEvent from waiting on per-tab work. That keeps the host and other tabs
alive. It does not make the operations above respect the remaining budget, so with it applied a tab still stays busy for the
extra time each of them spends, and a snapshot whose pause stalls still holds the capture lock.

Minimal reproduction

Each case uses the server browser with controlled timing (fake clock or stubbed Playwright/CDP calls); no real site is needed.

  1. Queue time, waitFor (same for evaluate, select, type, hover, drag): on one tab, start an action that takes 7 s.
    While it runs, send waitFor with timeoutMs: 9000 for a selector that never appears. Expected: the wait gives up about
    9 s after it was sent. Actual: it starts at 7 s with a fresh 9 s and gives up at about 16 s.
  2. select: stub the <select> locator so evaluate resolves after 7 s and selectOption never resolves. Call
    select with timeoutMs: 9000. Actual: selectOption is called with timeout: 9000, so the call ends at about 16 s.
  3. Snapshot pause: attach a viewer whose pause() never resolves. Request a snapshot, then advance the clock past 16 s.
    Actual: the capture never starts (no snapshot stage has run), the capture lock is still held, and a second snapshot on
    the tab is still waiting. Resolving the pause lets both complete.
  4. open on a stalled page: serve a page at / that responds at once and contains <img src="/stall.png">, where
    /stall.png never responds. Call preview_open with that URL. Actual: the open returns after about 15 s, although
    the document committed and rendered within about a second. Expected: it returns soon after the main document commits (or after
    domcontentloaded), reporting loading: true.
  5. press: stub page.keyboard.press to never resolve. Send press with any timeoutMs. Actual: the call never settles on
    the host; only the broker's own timeout ends it for the caller.

Expected behaviour

  • Every operation receives the time remaining on its request (the deadline computed when the request arrived), not a fresh
    timeoutMs, and sequential steps inside one operation share that remainder. A zero or negative remainder is refused before
    dispatch rather than passed to Playwright, where 0 disables the timeout.
  • press, scroll and type keyboard steps are bounded by the same remainder.
  • open and URL navigate return once the page is usable (commit or domcontentloaded) and report loading: true,
    rather than spending the navigation budget on load; waitFor remains the way to wait for more.
  • A snapshot's budget covers acquiring the capture lock, pausing viewers and recording, the capture itself, and resuming. If
    a pause or resume does not answer in time, the snapshot fails with a timeout that names that stage, and the capture lock is
    released, so the tab can take the next snapshot or stop a recording.
  • Expired work never resumes later and acts on the page after its caller has been told it timed out (the existing rule that
    possibly applied actions are never replayed still holds).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions