AI Agent News/stories/stagehand-adds-browser-side-wait-for-function-across-its-sdks.md

Browsers

Stagehand adds browser-side wait_for_function across its SDKs

Stagehand's SDKs now expose a wait that runs a predicate inside the browser page on each poll. The change covers the Python, TypeScript and Go SDKs and ships in a prerelease build of the Python package.

Source: github.com/browserbase/stagehand/releases/tag/stagehand-python%404.3.0a0.dev1626

The change registers page.wait_for_function and connects it to the extension controller and runtime. TypeScript callers use waitForFunction(expression, arg?, options?), Python callers use wait_for_function with keyword arguments for arg, polling and timeout, and Go exposes WaitForFunction. As in Playwright, an expression that evaluates to a function is called on every poll and receives the optional JSON argument.

By default each SDK polls with requestAnimationFrame or an interval and sets no deadline. Passing a timeout bounds the wait, and an omitted or zero timeout also removes the client response deadline. JSON result keys survive a roundtrip through opaque wire metadata, including keys named toString, constructor and hasOwnProperty in nested payloads.

The pull request reports 9 real-Chrome tests covering main-world access, async predicates, custom intervals, error propagation, navigation recovery, concurrent waits and timeout-zero closure. It is the second of two stacked pull requests and depends on #3179, which holds the polling, navigation recovery and cleanup code.

Why it matters if you build agents

Agent code that polls the page itself for a condition can switch to the built-in wait in any of the three SDKs and pass a timeout where it needs one. Without a timeout, a predicate that never becomes true will keep the wait running with no client-side deadline.

Get stories like this every weekday

One short email with the day's agent tooling news.

Subscribe