Quick start goto() Navigate the page to a URL. Options that configure this operation. Maximum wait time in milliseconds.
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to
"domcontentloaded".
The final main-document response, or null when no network response was produced.
reload() Reload the current page. Options that configure this operation. Whether to bypass the browser cache.
Maximum wait time in milliseconds.
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to
"domcontentloaded".
The final main-document response, or null when no network response was produced.
goBack() Navigate backward in the page history. Options that configure this operation. Maximum wait time in milliseconds.
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to
"domcontentloaded".
The final main-document response, or null when no history navigation occurred or no network response was produced.
goForward() Navigate forward in the page history. Options that configure this operation. Maximum wait time in milliseconds.
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to
"domcontentloaded".
The final main-document response, or null when no history navigation occurred or no network response was produced.
click() Click at page coordinates. The horizontal page coordinate.
The vertical page coordinate.
Options that configure this operation. The mouse button to use: "left", "middle", or "right".
The number of clicks to dispatch.
Resolves after the operation completes.
hover() Move the pointer to page coordinates. The horizontal page coordinate.
The vertical page coordinate.
Resolves after the operation completes.
Scroll from page coordinates by the supplied deltas. The horizontal page coordinate.
The vertical page coordinate.
Horizontal scroll distance.
Vertical scroll distance.
Resolves after the operation completes.
dragAndDrop() Drag from one page coordinate to another. The drag origin’s horizontal coordinate.
The drag origin’s vertical coordinate.
The drop target’s horizontal coordinate.
The drop target’s vertical coordinate.
Options that configure this operation. The mouse button to use: "left", "middle", or "right".
The input delay in milliseconds.
The number of intermediate pointer moves.
options.route PageDragAndDropRoutePoint[]
An ordered mouse route to follow instead of generating linear intermediate moves. The explicit
toX and toY coordinates remain the final point. A route point’s horizontal coordinate.
A route point’s vertical coordinate.
Resolves after the operation completes.
type() Type text at the current input target. Options that configure this operation. The input delay in milliseconds.
Whether to simulate occasional typing mistakes.
Resolves after the operation completes.
keyPress() Send a keyboard key press to the page. The keyboard key to send.
Options that configure this operation. The input delay in milliseconds.
Resolves after the operation completes.
evaluate() Evaluate JavaScript in the page and return its result. expression string | ((arg: Arg) => R | Promise<R>)
JavaScript source or a function to evaluate.
An optional argument passed to the function.
on() Subscribe to console messages from this page and its page-owned sessions. Stagehand
delivers each message using the underlying "Runtime.consoleAPICalled" event envelope. The console event name. Currently, the only supported value is "console".
A callback that receives the event method, raw parameters, session ID, target ID,
and page ID. Async callbacks may overlap and are not awaited by later page calls.
A subscription handle whose unsubscribe() method stops delivery.
CDPSubscription unsubscribe(): Promise<void> removes the listener locally and from the Stagehand runtime.
Repeated calls share the completed cleanup. A failed runtime request can be retried by calling
unsubscribe() again.addInitScript() Run a script before other scripts whenever the page navigates. A function, JavaScript source string, or object with exactly one of path and content.
An optional JSON-serializable argument. Valid only when script is a function.
Resolves after the operation completes.
Set additional HTTP headers for this page. HTTP header names and values.
Resolves after the operation completes.
setViewportSize() Set the page viewport dimensions. Viewport width in CSS pixels.
Viewport height in CSS pixels.
options PageSetViewportSizeOptions
Options that configure this operation. options.deviceScaleFactor The device scale factor.
Resolves after the operation completes.
waitForLoadState() Wait until the page reaches a load state. The state to wait for: "load", "domcontentloaded", or "networkidle".
Maximum wait time in milliseconds.
Resolves after the operation completes.
waitForTimeout() Wait for a fixed number of milliseconds. The number of milliseconds to wait.
Resolves after the operation completes.
waitForSelector() Wait for a selector to reach the requested state. options PageWaitForSelectorOptions
Options that configure this operation. Whether to traverse shadow roots. Closed roots require a navigated page; see the locator reference . options.state PageWaitForSelectorOptions['state']
The state to wait for: "attached", "detached", "visible", or "hidden".
The operation timeout in milliseconds.
screenshot() Capture a screenshot of the page. Options that configure this operation. options.animations ScreenshotOptions['animations']
How to handle active animations: "disabled" or "allow".
options.caret ScreenshotOptions['caret']
How to render the text caret: "hide" or "initial".
The screenshot crop rectangle. The positive height in CSS pixels.
The positive width in CSS pixels.
The horizontal coordinate.
Whether to capture the full scrollable page. Cannot be combined with clip.
Page-created locators for elements to obscure. Every locator must belong to this page.
Whether to use a transparent background.
A file path where the image is also written.
JPEG quality as an integer from 0 to 100. Valid only when type is "jpeg".
options.scale ScreenshotOptions['scale']
Whether to use "css" or "device" pixel scale.
CSS applied while taking the screenshot.
The non-negative operation timeout in milliseconds.
options.type ScreenshotOptions['type']
The image format: "png" or "jpeg".
The screenshot image bytes.
snapshot() Capture the page’s accessibility-oriented DOM snapshot. Options that configure this operation. Whether to include iframe content.
The operation result. The snapshot XPath lookup.
Return the WebMCP tools registered on the page. Options that configure tool discovery. Maximum time in milliseconds to wait for registered tools.
url() Return the page’s current URL. title() Return the page’s current document title. close() Close the page. Resolves after the operation completes.
locator() Create a locator for a CSS selector on this page. Quick start goto() Navigate the page to a URL. wait_until LoadState | Literal['load', 'domcontentloaded', 'networkidle']
The load state to wait for. Defaults to "domcontentloaded".
Maximum wait time in milliseconds.
The final main-document response, or None when no network response was produced.
reload() Reload the current page. wait_until LoadState | Literal['load', 'domcontentloaded', 'networkidle']
The load state to wait for. Defaults to "domcontentloaded".
Maximum wait time in milliseconds.
Whether to bypass the browser cache.
The final main-document response, or None when no network response was produced.
go_back() Navigate backward in the page history. wait_until LoadState | Literal['load', 'domcontentloaded', 'networkidle']
The load state to wait for. Defaults to "domcontentloaded".
Maximum wait time in milliseconds.
The final main-document response, or None when no history navigation occurred or no network response was produced.
go_forward() Navigate forward in the page history. wait_until LoadState | Literal['load', 'domcontentloaded', 'networkidle']
The load state to wait for. Defaults to "domcontentloaded".
Maximum wait time in milliseconds.
The final main-document response, or None when no history navigation occurred or no network response was produced.
click() Click at page coordinates. The horizontal page coordinate.
The vertical page coordinate.
button MouseButton | Literal['left', 'right', 'middle']
The mouse button to use.
The number of clicks to dispatch.
Resolves after the operation completes.
hover() Move the pointer to page coordinates. The horizontal page coordinate.
The vertical page coordinate.
Resolves after the operation completes.
Scroll from page coordinates by the supplied deltas. The horizontal page coordinate.
The vertical page coordinate.
Horizontal scroll distance.
Vertical scroll distance.
Resolves after the operation completes.
drag_and_drop() Drag from one page coordinate to another. The drag origin’s horizontal coordinate.
The drag origin’s vertical coordinate.
The drop target’s horizontal coordinate.
The drop target’s vertical coordinate.
button MouseButton | Literal['left', 'right', 'middle']
The mouse button to use.
The number of intermediate pointer moves.
An optional input delay in milliseconds.
route Sequence[PageDragAndDropRoutePoint | Mapping[str, float]] | None
An ordered mouse route to follow instead of generating linear intermediate moves. The explicit
to_x and to_y coordinates remain the final point. A route point’s horizontal coordinate.
A route point’s vertical coordinate.
Resolves after the operation completes.
type() Type text at the current input target. An optional input delay in milliseconds.
Whether to simulate occasional typing mistakes.
Resolves after the operation completes.
key_press() Send a keyboard key press to the page. The keyboard key to send.
An optional input delay in milliseconds.
Resolves after the operation completes.
evaluate() Evaluate JavaScript in the page and return its result. JavaScript source or a function to evaluate.
result_type type[EvaluateResult] | None
An optional Python type used to validate the result.
result JsonValue | EvaluateResult
The operation result.
on() Subscribe to console messages from this page and its page-owned sessions. Stagehand
delivers each message using the underlying "Runtime.consoleAPICalled" event envelope. The console event name. Currently, the only supported value is "console".
A sync or async callback that receives the event method, raw parameters, session
ID, target ID, and page ID. Async callbacks may overlap and are not awaited by
later page calls.
A subscription handle whose unsubscribe() method stops delivery.
CDPSubscription await subscription.unsubscribe() removes the listener locally and from the Stagehand runtime.
Repeated calls await the same successful cleanup. Failed cleanup can be retried. If the caller is
cancelled while awaiting cleanup, the shared cleanup task continues in the background.add_init_script() Run a script before other scripts whenever the page navigates. JavaScript source or a path to a JavaScript file on the SDK caller’s machine.
Resolves after the operation completes.
Set additional HTTP headers for this page. HTTP header names and values.
Resolves after the operation completes.
set_viewport_size() Set the page viewport dimensions. Viewport width in CSS pixels.
Viewport height in CSS pixels.
Resolves after the operation completes.
wait_for_load_state() Wait until the page reaches a load state. state LoadState | Literal['load', 'domcontentloaded', 'networkidle']
The state to wait for: "load", "domcontentloaded", or "networkidle".
Maximum wait time in milliseconds.
Resolves after the operation completes.
wait_for_timeout() Wait for a fixed number of milliseconds. The number of milliseconds to wait.
Resolves after the operation completes.
wait_for_selector() Wait for a selector to reach the requested state. state State | Literal['attached', 'detached', 'visible', 'hidden']
The state to wait for: "attached", "detached", "visible", or "hidden".
Maximum wait time in milliseconds.
Whether to traverse shadow roots. Closed roots require a navigated page; see the locator reference . screenshot() Capture a screenshot of the page. animations Animations | Literal['disabled', 'allow']
How to handle CSS animations: "disabled" or "allow".
caret Caret | Literal['hide', 'initial']
How to render the text caret: "hide" or "initial".
clip PageScreenshotClip | None
The region to capture. The positive height in CSS pixels.
The positive width in CSS pixels.
The horizontal coordinate.
Whether to capture the full scrollable page. Cannot be combined with clip.
A path where the image is also written.
Page-created locators for elements to obscure. Every locator must belong to this page.
The CSS color used for masks.
Whether to use a transparent background.
JPEG quality as an integer from 0 to 100. Valid only when type is "jpeg".
scale Scale | Literal['css', 'device']
Whether to use "css" or "device" pixel scale.
CSS applied while taking the screenshot.
Maximum non-negative wait time in milliseconds.
type ScreenshotType | Literal['png', 'jpeg']
The image format: "png" or "jpeg".
snapshot() Capture the page’s accessibility-oriented DOM snapshot. Whether to include iframe content.
The operation result. The snapshot XPath lookup.
Return the WebMCP tools registered on the page. Maximum time in milliseconds to wait for registered tools.
url() Return the page’s current URL. title() Return the page’s current document title. close() Close the page. Resolves after the operation completes.
locator() Create a locator for a CSS selector on this page. Quick start Every method that talks to the browser takes a context.Context first and returns an error last; the local Locator() accessor takes neither. Options are passed as pointer structs; pass nil for defaults. Goto() Navigate the page to a URL. Options that configure this operation. Pass nil for defaults. Maximum wait time in milliseconds.
The target load state: LoadStateLoad, LoadStateDOMContentLoaded, or
LoadStateNetworkIdle. Defaults to LoadStateDOMContentLoaded.
The final main-document response, or nil when no network response was produced.
Reload() Reload the current page. Options that configure this operation. Pass nil for defaults. Whether to bypass the browser cache.
Maximum wait time in milliseconds.
The target load state: LoadStateLoad, LoadStateDOMContentLoaded, or
LoadStateNetworkIdle. Defaults to LoadStateDOMContentLoaded.
The final main-document response, or nil when no network response was produced.
GoBack() Navigate backward in the page history. Options that configure this operation. Pass nil for defaults. Maximum wait time in milliseconds.
The target load state: LoadStateLoad, LoadStateDOMContentLoaded, or
LoadStateNetworkIdle. Defaults to LoadStateDOMContentLoaded.
The final main-document response, or nil when no history navigation occurred or no network response was produced.
GoForward() Navigate forward in the page history. Options that configure this operation. Pass nil for defaults. Maximum wait time in milliseconds.
The target load state: LoadStateLoad, LoadStateDOMContentLoaded, or
LoadStateNetworkIdle. Defaults to LoadStateDOMContentLoaded.
The final main-document response, or nil when no history navigation occurred or no network response was produced.
Click() Click at page coordinates. The horizontal page coordinate.
The vertical page coordinate.
Options that configure this operation. Pass nil for defaults. The mouse button to use: MouseButtonLeft, MouseButtonMiddle, or MouseButtonRight.
The number of clicks to dispatch.
Returns nil after the operation completes.
Hover() Move the pointer to page coordinates. The horizontal page coordinate.
The vertical page coordinate.
Returns nil after the operation completes.
Scroll from page coordinates by the supplied deltas. The horizontal page coordinate.
The vertical page coordinate.
Horizontal scroll distance.
Vertical scroll distance.
Returns nil after the operation completes.
DragAndDrop() Drag from one page coordinate to another. The drag origin’s horizontal coordinate.
The drag origin’s vertical coordinate.
The drop target’s horizontal coordinate.
The drop target’s vertical coordinate.
Options that configure this operation. Pass nil for defaults. The mouse button to use: MouseButtonLeft, MouseButtonMiddle, or MouseButtonRight.
The input delay in milliseconds.
The number of intermediate pointer moves.
options.Route []PageDragAndDropRoutePoint
An ordered mouse route to follow instead of generating linear intermediate moves. The explicit
toX and toY coordinates remain the final point. A route point’s horizontal coordinate.
A route point’s vertical coordinate.
Returns nil after the operation completes.
Type() Type text at the current input target. Options that configure this operation. Pass nil for defaults. The input delay in milliseconds.
Whether to simulate occasional typing mistakes.
Returns nil after the operation completes.
KeyPress() Send a keyboard key press to the page. The keyboard key to send.
Options that configure this operation. Pass nil for defaults. The input delay in milliseconds.
Returns nil after the operation completes.
Evaluate() Evaluate JavaScript in the page and return its result. Evaluate returns the raw JSON
value; use the package-level generic EvaluateAs to decode the result into a Go type. JavaScript source to evaluate.
The operation result as raw JSON. EvaluateAs[T] decodes it into T instead.
On() Subscribe to console messages from this page and its page-owned sessions. Stagehand
delivers each message using the underlying "Runtime.consoleAPICalled" event envelope. The console event name. Currently, the only supported value is PageEventNameConsole.
A callback that receives the event method, raw parameters, session ID, target ID,
and page ID. Listeners are not awaited by later page calls.
result (*CDPSubscription, error)
A subscription handle whose Close() method stops delivery.
CDPSubscription Close(ctx context.Context) error removes the listener locally and from the Stagehand runtime.
Repeated calls after successful cleanup return nil. Concurrent calls share the active cleanup;
a failed attempt can be retried.AddInitScript() Run a script before other scripts whenever the page navigates. JavaScript source. Go functions and file paths are not interpreted.
Returns nil after the operation completes.
Set additional HTTP headers for this page. HTTP header names and values, as a map[string]string.
Returns nil after the operation completes.
SetViewportSize() Set the page viewport dimensions. Viewport width in CSS pixels.
Viewport height in CSS pixels.
options *PageSetViewportSizeOptions
Options that configure this operation. Pass nil for defaults. options.DeviceScaleFactor The device scale factor.
Returns nil after the operation completes.
WaitForLoadState() Wait until the page reaches a load state. The state to wait for: LoadStateLoad, LoadStateDOMContentLoaded, or LoadStateNetworkIdle.
Maximum wait time in milliseconds. Pass nil for the default.
Returns nil after the operation completes.
WaitForTimeout() Wait for a fixed number of milliseconds. The number of milliseconds to wait.
Returns nil after the operation completes.
WaitForSelector() Wait for a selector to reach the requested state. options *PageWaitForSelectorOptions
Options that configure this operation. Pass nil for defaults. Whether to traverse shadow roots. Closed roots require a navigated page; see the locator reference . options.State *PageWaitForSelectorOptionsState
The state to wait for: PageWaitForSelectorOptionsStateAttached,
PageWaitForSelectorOptionsStateDetached, PageWaitForSelectorOptionsStateVisible, or
PageWaitForSelectorOptionsStateHidden.
The operation timeout in milliseconds.
Screenshot() Capture a screenshot of the page. There is no path option in Go; write the returned
bytes yourself, for example with os.WriteFile. Options that configure this operation. Pass nil for defaults. options.Animations *PageScreenshotOptionsAnimations
How to handle active animations: PageScreenshotOptionsAnimationsDisabled or
PageScreenshotOptionsAnimationsAllow.
options.Caret *PageScreenshotOptionsCaret
How to render the text caret: PageScreenshotOptionsCaretHide or
PageScreenshotOptionsCaretInitial.
The screenshot crop rectangle. The positive height in CSS pixels.
The positive width in CSS pixels.
The horizontal coordinate.
Whether to capture the full scrollable page. Cannot be combined with options.Clip.
Page-created locators for elements to obscure in the screenshot. Create each with
page.Locator("..."); every mask locator must belong to the page being captured.
Whether to use a transparent background.
JPEG quality as an integer from 0 to 100. Valid only when options.Type is
PageScreenshotOptionsTypeJPEG.
options.Scale *PageScreenshotOptionsScale
Whether to use PageScreenshotOptionsScaleCSS or PageScreenshotOptionsScaleDevice.
CSS applied while taking the screenshot.
The non-negative operation timeout in milliseconds.
options.Type *PageScreenshotOptionsType
The image format: PageScreenshotOptionsTypePNG or PageScreenshotOptionsTypeJPEG.
The screenshot image bytes.
Snapshot() Capture the page’s accessibility-oriented DOM snapshot. Options that configure this operation. Pass nil for defaults. Whether to include iframe content.
The operation result. The snapshot XPath lookup.
Return the WebMCP tools registered on the page. Options that configure tool discovery. Pass nil for defaults. Maximum time in milliseconds to wait for registered tools.
URL() Return the page’s current URL. Title() Return the page’s current document title. Close() Close the page. Returns nil after the operation completes.
Locator() Create a locator for a CSS selector on this page.