Overview
Thepage object is the main interface for interacting with browser pages in Stagehand. It provides standard browser automation capabilities for navigation, interaction, and page inspection.
Access the page object through your Stagehand instance:
Navigation Methods
goto()
Navigate the page to a URL and wait for a lifecycle state.The URL to navigate to. Can be absolute or relative.
When to consider navigation succeeded.Options:
"load"- Wait for the load event"domcontentloaded"- Wait for DOMContentLoaded event (default)"networkidle"- Wait for network to be idle
"domcontentloaded"Maximum time to wait for navigation in milliseconds.Default:
15000reload()
Reload the current page.When to consider reload complete. See
goto() for options.Maximum time to wait for reload in milliseconds.Default:
15000Whether to bypass the browser cache.Default:
falsegoBack()
Navigate back in browser history.When to consider navigation complete.
Maximum time to wait in milliseconds.Default:
15000goForward()
Navigate forward in browser history.When to consider navigation complete.
Maximum time to wait in milliseconds.Default:
15000Page Information
url()
Get the current page URL (synchronous).title()
Get the current page title.Interaction Methods
click()
Click at absolute page coordinates.X coordinate in CSS pixels.
Y coordinate in CSS pixels.
Optional click configuration.
type()
Type text into the page (dispatches keyboard events).The text to type.
Optional typing configuration.
locator()
Create a locator for querying elements.CSS selector or XPath for the element.
Locator object for interacting with the element.
Evaluation
evaluate()
Evaluate JavaScript code in the page context.JavaScript expression as a string or a function to execute in the page context.
Optional argument to pass to the function.
Screenshot
screenshot()
Capture a screenshot of the page.Whether to capture the full scrollable page.Default:
falseViewport
setViewportSize()
Set the page viewport size.Viewport width in CSS pixels.
Viewport height in CSS pixels.
Device scale factor (pixel ratio).Default:
1Wait Methods
waitForLoadState()
Wait for the page to reach a specific lifecycle state.The lifecycle state to wait for.Options:
"load", "domcontentloaded", "networkidle"Maximum time to wait in milliseconds.Default:
15000Code Examples
Types
LoadState
"load"- Wait for theloadevent (all resources loaded)"domcontentloaded"- Wait for theDOMContentLoadedevent (DOM is ready)"networkidle"- Wait for network connections to be idle
AnyPage
AnyPage type represents any compatible page object.
Error Handling
Page methods may throw the following errors:- Navigation Errors - Timeout or network issues during navigation
- Evaluation Errors - JavaScript execution errors in
evaluate() - Interaction Errors - Failed clicks or typing operations
- Screenshot Errors - Issues capturing screenshots

