Skip to main content
A Page combines deterministic browser controls with Stagehand’s natural-language act, observe, and extract methods. Navigation methods return the main-document Response, when the navigation produces one.

Quick start

goto()

Navigate the page to a URL.
string
The destination URL.
PageNavigationOptions
Options that configure this operation.
number
Maximum wait time in milliseconds.
LoadState
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to "domcontentloaded".
Promise<Response | null>
The final main-document response, or null when no network response was produced.

reload()

Reload the current page.
PageReloadOptions
Options that configure this operation.
boolean
Whether to bypass the browser cache.
number
Maximum wait time in milliseconds.
LoadState
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to "domcontentloaded".
Promise<Response | null>
The final main-document response, or null when no network response was produced.

goBack()

Navigate backward in the page history.
PageNavigationOptions
Options that configure this operation.
number
Maximum wait time in milliseconds.
LoadState
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to "domcontentloaded".
Promise<Response | null>
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.
PageNavigationOptions
Options that configure this operation.
number
Maximum wait time in milliseconds.
LoadState
The target load state: "load", "domcontentloaded", or "networkidle". Defaults to "domcontentloaded".
Promise<Response | null>
The final main-document response, or null when no history navigation occurred or no network response was produced.

click()

Click at page coordinates.
number
The horizontal page coordinate.
number
The vertical page coordinate.
PageClickOptions
Options that configure this operation.
MouseButton
The mouse button to use: "left", "middle", or "right".
number
The number of clicks to dispatch.
Promise<void>
Resolves after the operation completes.

hover()

Move the pointer to page coordinates.
number
The horizontal page coordinate.
number
The vertical page coordinate.
Promise<void>
Resolves after the operation completes.

scroll()

Scroll from page coordinates by the supplied deltas.
number
The horizontal page coordinate.
number
The vertical page coordinate.
number
Horizontal scroll distance.
number
Vertical scroll distance.
Promise<void>
Resolves after the operation completes.

dragAndDrop()

Drag from one page coordinate to another.
number
The drag origin’s horizontal coordinate.
number
The drag origin’s vertical coordinate.
number
The drop target’s horizontal coordinate.
number
The drop target’s vertical coordinate.
PageDragAndDropOptions
Options that configure this operation.
MouseButton
The mouse button to use: "left", "middle", or "right".
number
The input delay in milliseconds.
number
The number of intermediate pointer moves.
PageDragAndDropRoutePoint[]
An ordered mouse route to follow instead of generating linear intermediate moves. The explicit toX and toY coordinates remain the final point.
number
A route point’s horizontal coordinate.
number
A route point’s vertical coordinate.
Promise<void>
Resolves after the operation completes.

type()

Type text at the current input target.
string
The text to type.
PageTypeOptions
Options that configure this operation.
number
The input delay in milliseconds.
boolean
Whether to simulate occasional typing mistakes.
Promise<void>
Resolves after the operation completes.

keyPress()

Send a keyboard key press to the page.
string
The keyboard key to send.
PageKeyPressOptions
Options that configure this operation.
number
The input delay in milliseconds.
Promise<void>
Resolves after the operation completes.

evaluate()

Evaluate JavaScript in the page and return its result.
string | ((arg: Arg) => R | Promise<R>)
JavaScript source or a function to evaluate.
Arg
An optional argument passed to the function.
Promise<R>
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.
PageEventName
The console event name. Currently, the only supported value is "console".
PageEventListener
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.
Promise<CDPSubscription>
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.
InitScriptSource<Arg>
A function, JavaScript source string, or object with exactly one of path and content.
Arg
An optional JSON-serializable argument. Valid only when script is a function.
Promise<void>
Resolves after the operation completes.

setExtraHTTPHeaders()

Set additional HTTP headers for this page.
Record<string, string>
HTTP header names and values.
Promise<void>
Resolves after the operation completes.

setViewportSize()

Set the page viewport dimensions.
number
Viewport width in CSS pixels.
number
Viewport height in CSS pixels.
PageSetViewportSizeOptions
Options that configure this operation.
number
The device scale factor.
Promise<void>
Resolves after the operation completes.

waitForLoadState()

Wait until the page reaches a load state.
LoadState
The state to wait for: "load", "domcontentloaded", or "networkidle".
number
Maximum wait time in milliseconds.
Promise<void>
Resolves after the operation completes.

waitForTimeout()

Wait for a fixed number of milliseconds.
number
The number of milliseconds to wait.
Promise<void>
Resolves after the operation completes.

waitForSelector()

Wait for a selector to reach the requested state.
string
The selector to target.
PageWaitForSelectorOptions
Options that configure this operation.
boolean
Whether to traverse shadow roots. Closed roots require a navigated page; see the locator reference.
PageWaitForSelectorOptions['state']
The state to wait for: "attached", "detached", "visible", or "hidden".
number
The operation timeout in milliseconds.
Promise<boolean>
The operation result.

screenshot()

Capture a screenshot of the page.
ScreenshotOptions
Options that configure this operation.
ScreenshotOptions['animations']
How to handle active animations: "disabled" or "allow".
ScreenshotOptions['caret']
How to render the text caret: "hide" or "initial".
PageScreenshotClip
The screenshot crop rectangle.
number
The positive height in CSS pixels.
number
The positive width in CSS pixels.
number
The horizontal coordinate.
number
The vertical coordinate.
boolean
Whether to capture the full scrollable page. Cannot be combined with clip.
Locator[]
Page-created locators for elements to obscure. Every locator must belong to this page.
string
The CSS mask color.
boolean
Whether to use a transparent background.
string
A file path where the image is also written.
number
JPEG quality as an integer from 0 to 100. Valid only when type is "jpeg".
ScreenshotOptions['scale']
Whether to use "css" or "device" pixel scale.
string
CSS applied while taking the screenshot.
number
The non-negative operation timeout in milliseconds.
ScreenshotOptions['type']
The image format: "png" or "jpeg".
Promise<Uint8Array>
The screenshot image bytes.

snapshot()

Capture the page’s accessibility-oriented DOM snapshot.
PageSnapshotOptions
Options that configure this operation.
boolean
Whether to include iframe content.
Promise<SnapshotResult>
The operation result.
string
The formatted page tree.
object
The snapshot URL lookup.
object
The snapshot XPath lookup.

tools()

Return the WebMCP tools registered on the page.
WebMCPToolsOptions
Options that configure tool discovery.
number
Maximum time in milliseconds to wait for registered tools.
Promise<WebMCPTool[]>
The callable WebMCP tools registered on the page. See the WebMCP reference.

url()

Return the page’s current URL.
Promise<string>
The operation result.

title()

Return the page’s current document title.
Promise<string>
The operation result.

close()

Close the page.
Promise<void>
Resolves after the operation completes.

locator()

Create a locator for a CSS selector on this page.
string
The selector to target.
Locator
The operation result.