Skip to content

feat(browser): browser_info waits for text to appear or go - #955

Merged
omartelo merged 2 commits into
mainfrom
feat/browser-wait-for
Oct 28, 2026
Merged

omartelo merged 2 commits into
mainfrom
feat/browser-wait-for

Conversation

@omartelo

Copy link
Copy Markdown
Collaborator

Summary

After a click that starts a fetch, an agent re-reads the session browser with browser_info until the result shows. browser_info now takes two optional parameters so it can wait once instead:

  • wait_for: text that should appear
  • wait_gone: text that should disappear

Both are a case-sensitive substring of the page's visible text (document.body.innerText, the whole page, not only the viewport). The read polls every 100 ms (textPoll) for up to 20 s (maxTextWait, which leaves the page read its own pageWait under the client's 60 s openCall). On timeout it answers the page anyway with a wait: timed out, this is the page as it stands line, not an error. A read failing mid-wait (the page between two documents after a navigating click) counts as not yet; a Chrome that died ends the wait and the page read reports it. Without the parameters, behavior is unchanged. No new MCP tool; browser_info stays read-only. The CLI's lich browser info takes no flags today, so it does not mirror these.

The timeout line is English and outside the i18n catalog, like every other page-answer line (url:, downloaded:, ...).

Contract

  • browser.Info takes the new api.BrowserInfoOptions (id, waitFor, waitGone) instead of SessionIDOptions; BrowserPageInfo gains waitTimedOut. api/testdata/contract.golden updated.
  • Page gains HasText. The three existing test calls to Service.Read (session_downloads_test.go, downloads_live_test.go) change only their options type: the contract changed.

Test plan

  • internal/browser/wait_test.go (fake page): text appears on the third read, text goes on the second, case-sensitive miss times out within the shortened bound and still answers the page, no params reads no text, a Chrome dying mid-wait stops the wait.
  • internal/browser/wait_live_test.go (skips without a Chromium-family browser): a page writes Saved over Loading 300 ms after load, below the fold; wait_for and wait_gone both see it, and a case-mismatched wait times out with the page answered. 10/10 with -race.
  • internal/cli: the timeout line sits after the title.
  • Local gate: gofmt -l ., go vet ./..., go test ./... green; native/ gofmt, go vet ./..., go build ./... green.

browser_info takes wait_for and wait_gone: a case-sensitive substring of
the page's visible text (document.body.innerText, the whole page). The read
polls every 100 ms for up to 20 s, then answers the page anyway, with a
line saying the wait timed out, so the agent stops re-reading in a loop
after a click that starts a fetch.

browser.Info now takes BrowserInfoOptions instead of SessionIDOptions;
the three tests calling Service.Read follow that contract change.
On Windows the TempDir cleanup registered inside mkTmp ran before
Service.Cleanup closed Chrome, and failed on a file Chrome still held.
@omartelo
omartelo force-pushed the feat/browser-wait-for branch from 02dc21f to df9ef63 Compare October 28, 2026 13:05
@omartelo
omartelo merged commit 85d523d into main Oct 28, 2026
7 checks passed
@omartelo
omartelo deleted the feat/browser-wait-for branch October 28, 2026 13:11
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