WebBrowser

class WebBrowser(context: Context, val maxContentTokens: Int, val actionTimeoutMs: Long, val navigationTimeoutMs: Long, val viewport: BrowserViewport = BrowserViewport.Desktop, val screenshots: Boolean = true, val screenshotOnNavigate: Boolean = false) : Capability(source)

A web browser for the agent, with the tools and result texts of the Pydantic AI Harness browser capability (navigate, snapshot, click, type_text, press_key, select_option, hover, wait_for, get_text, scroll, go_back, go_forward), on an off-screen Android WebView.

Selectors are CSS selectors, aria-ref=eN handles from snapshot, or x,y CSS-pixel coordinates. Only http(s) pages load; results are capped at maxContentTokens (4 characters per token), keeping the head.

screenshot(full_page?) returns the page as a PNG for vision models (Pydantic AI ToolReturn.content, as the Harness browser does), and screenshotOnNavigate adds one to every navigate result; both are capped at 5 MB like the Harness'. With screenshots, every call that changes the page (navigate, click, type, keys, scroll, back, forward) also attaches a smaller screenshot for the chat's steps view, with the element the call acted on outlined, as agent computer views do; the model does not get those.

Constructors

Link copied to clipboard
constructor(context: Context, maxContentTokens: Int, actionTimeoutMs: Long, navigationTimeoutMs: Long, viewport: BrowserViewport = BrowserViewport.Desktop, screenshots: Boolean = true, screenshotOnNavigate: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard
open override val instructions: String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The page size the browser presents, in CSS pixels; screenshots have this size.

Functions

Link copied to clipboard
suspend fun close()

Stop and free the WebView.

Link copied to clipboard
open suspend fun context(): String?
Link copied to clipboard
suspend fun navigate(url: String, timeoutMs: Long? = null): String
Link copied to clipboard
open suspend override fun tools(): List<AgentTool>