Documentation Index
Fetch the complete documentation index at: https://mintlify.com/l-xiaoshen/handstage/llms.txt
Use this file to discover all available pages before exploring further.
Page represents a single top-level browser tab. You receive a Page from context.newPage(), context.activePage(), or context.pages(). Each Page owns its own CDP session and manages all out-of-process iframe child sessions internally.
Navigation
page.goto
Navigate the page to a URL and wait for a lifecycle state.
The URL to navigate to.
Lifecycle event to wait for before resolving. One of
"load", "domcontentloaded", or "networkidle".Maximum navigation time in milliseconds.
Promise<Response | null>
page.reload
Reload the current page.
Lifecycle event to wait for. One of
"load", "domcontentloaded", or "networkidle".Maximum reload time in milliseconds.
When
true, the browser bypasses its cache for the reload.Promise<Response | null>
page.goBack
Navigate to the previous entry in browser history. Returns null if there is no previous entry.
Lifecycle event to wait for after navigating back.
Maximum time to wait in milliseconds.
Promise<Response | null>
page.goForward
Navigate to the next entry in browser history. Returns null if there is no forward entry.
Lifecycle event to wait for after navigating forward.
Maximum time to wait in milliseconds.
Promise<Response | null>
page.waitForLoadState
Wait until the page reaches the specified lifecycle state on the main frame.
One of
"load", "domcontentloaded", or "networkidle".Maximum time to wait in milliseconds.
Promise<void>
LoadState type
| Value | Fires when |
|---|---|
"load" | The load event fires on the window. |
"domcontentloaded" | The DOMContentLoaded event fires. |
"networkidle" | No network requests for at least 500 ms. |
Page information
page.url
Return the current page URL. This is a synchronous, cached value updated from CDP navigation events.
string
page.title
Return the current document title. Reads from the live document via Runtime.evaluate, falling back to navigation history if evaluation is unavailable.
Promise<string>
Capture
page.snapshot
Capture an accessibility tree snapshot of the page. The snapshot includes a formatted text tree suitable for LLM consumption, along with XPath and URL maps for element resolution.
When
true, iframe content is included in the accessibility tree.Promise<SnapshotResult>
SnapshotResult type
A human-readable accessibility tree as a formatted string.
Map from snapshot node references to their absolute XPath expressions.
Map from snapshot node references to their associated URLs (for links and iframes).
page.screenshot
Capture a screenshot of the page and return it as a Buffer.
Image format.
JPEG quality from 0–100. Only applies when
type is "jpeg".Capture the full scrollable page instead of the viewport. Cannot be combined with
clip.Restrict capture to a rectangle in CSS pixels:
{ x, y, width, height }. Cannot be combined with fullPage.Set to
"disabled" to fast-forward finite CSS animations and pause infinite ones before capture.Hide the text caret during capture (
"hide") or leave it as-is ("initial").Array of locators whose matched elements are covered with a colored overlay during capture.
CSS color for mask overlays.
Make the default page background transparent. PNG only.
File path to write the screenshot to after capture. The file extension determines the format when
type is not provided.Render scale.
"css" uses one pixel per CSS pixel; "device" uses the device pixel ratio.Additional CSS injected into every frame before capture and removed afterwards.
Maximum capture duration in milliseconds before a timeout error is thrown.
Promise<Buffer>
Locators and frames
page.locator
Create a Locator scoped to the current main frame. Supports CSS selectors and XPath.
A CSS selector, XPath expression (detected when starting with
/ or (), or text= prefix for text matching. Use explicit css=, xpath=, or text= prefixes to override auto-detection.Locator
See Locator — element interaction API reference for all locator methods.
page.frameLocator
Return a FrameLocator that scopes subsequent locator calls to the content of a matched iframe element. Mirrors Playwright’s API.
CSS selector for the iframe element.
FrameLocator
Scripts and headers
page.addInitScript
Register a script to run at document start for this page only. The script is replayed on each navigation and applied to any out-of-process iframe sessions adopted by this page.
A JavaScript expression string or a serializable function.
JSON-serializable argument passed to the script function.
Promise<void>
page.setExtraHTTPHeaders
Attach additional HTTP headers to every request sent by this page’s CDP sessions, including adopted out-of-process iframe sessions.
Key–value pairs of header names and values.
Promise<void>
Throws HandstagesSetExtraHTTPHeadersError if any session fails to apply the headers.
Console events
page.on
Subscribe to page events. Currently "console" is the supported event type.
The event name to listen for.
Callback invoked with a
ConsoleMessage object for each console event.Page (for chaining)
page.once
Subscribe to the next occurrence of an event, then automatically unsubscribe.
Page (for chaining)
page.off
Remove a previously registered event listener.
Page (for chaining)
Low-level CDP access
page.sendCDP
Send a raw CDP command through the page’s main session. Use this when you need access to CDP domains not otherwise exposed by the SDK.
The CDP method name, e.g.,
"Page.enable" or "Runtime.evaluate".Optional parameters for the CDP command.
Promise<unknown>
Utilities and evaluation
page.evaluate
Evaluate a JavaScript expression or function in the page’s main frame main world. If a function is provided, it is stringified and called with the optional argument. The return value must be JSON-serializable.
A JavaScript expression string or a serializable function.
JSON-serializable argument passed to the function. Ignored for string expressions.
Promise<R>
Throws HandstagesEvalError if the expression throws inside the page context.
page.waitForTimeout
Wait for a fixed number of milliseconds. Useful for debugging or adding deliberate pauses between actions.
Number of milliseconds to wait.
Promise<void>
page.waitForSelector
Wait for an element matching the selector to appear in (or disappear from) the DOM. Uses MutationObserver for efficiency and pierces shadow DOM by default. Supports iframe hop notation with >>.
CSS selector to wait for. Use
>> to hop into an iframe (e.g., "iframe#checkout >> .submit-btn").Element state to wait for.
Maximum time to wait in milliseconds.
When
true, search inside shadow DOM roots.Promise<boolean> — true when the condition is met.
page.click
Click at absolute viewport coordinates (CSS pixels). Dispatches mouseMoved → mousePressed → mouseReleased at the given point. Does not scroll — ensure the target is within the viewport first.
Horizontal coordinate in CSS pixels from the left edge of the viewport.
Vertical coordinate in CSS pixels from the top edge of the viewport.
Which mouse button to use.
Number of clicks to dispatch.
When
true, resolves the deepest element at the click coordinates and returns its absolute XPath. Returns undefined when XPath resolution fails.Promise<string> — The resolved XPath when returnXpath is true, otherwise an empty string.
page.setViewportSize
Override the page viewport to an exact CSS size and device scale factor. Useful for ensuring screenshots match a specific resolution.
Viewport width in CSS pixels.
Viewport height in CSS pixels.
Device pixel ratio. Values below
0.01 are clamped to 0.01.Promise<void>
page.deepLocator
Create a Locator that supports cross-iframe traversal using >> hop notation or deep XPath with iframe steps.
A CSS selector with optional
>> hops or an XPath expression including iframe steps.Locator
page.enableCursorOverlay
Enable a visual cursor overlay that tracks mouse position on the page. Injects a custom SVG cursor element into the page and keeps it in sync with pointer events. Useful for recording or debugging automation scripts.
Promise<void>
Tab lifecycle
page.close
Close this browser tab. Uses Target.closeTarget over CDP and waits up to 2 seconds for the target to disappear before releasing resources.
Promise<void>