Observe
See how to use observe() to discover actionable elements and analyze web page structure
Method Signatures
- TypeScript
Parameters
Natural language description of elements or actions to discover. If not provided, defaults to finding all interactive elements on the page.
Configure the AI model to use for this observation. Can be either:
- A string in the format
"provider/model"(e.g.,"openai/gpt-4o","anthropic/claude-sonnet-4-6") - An object with detailed configuration
Maximum time in milliseconds to wait for the observation to complete. Default varies by configuration.
Optional XPath selector to focus the observation on a specific part of the page. Useful for narrowing down the search area.
Optional: Specify which page to perform the observation on. Supports multiple browser automation libraries:
- Playwright: Native Playwright Page objects
- Puppeteer: Puppeteer Page objects
- Patchright: Patchright Page objects
- Stagehand Page: Stagehand’s wrapped Page object
Override the instance-level Defaults to the value set on the Stagehand constructor (which itself defaults to
serverCache setting for this request. When true, enables server-side caching. When false, disables it.Only applies when
env is "BROWSERBASE". Has no effect in local environments.true).Returns Promise<Action[]>
Array of discovered actionable elements, ordered by relevance.
XPath selector that precisely locates the element on the page.
Human-readable description of the element and its purpose.
Suggested interaction method for the element (e.g.,
"click", "fill", "type").Additional parameters for the suggested action, if applicable.
Built-in Support
Iframe and Shadow DOM interactions are supported out of the box. Stagehand automatically handles iframe traversal and shadow DOM elements without requiring additional configuration or flags.
Code Examples
- Basic Usage
- Custom Model
- Scoped
- Multi-Page
- Filter Results
Integration Patterns
Error Types
The following errors may be thrown by theobserve() method:
- StagehandError - Base class for all Stagehand-specific errors
- StagehandDomProcessError - Error occurred while processing the DOM
- StagehandEvalError - Error occurred while evaluating JavaScript in the page context
- StagehandIframeError - Unable to resolve iframe for the target element
- ContentFrameNotFoundError - Unable to obtain content frame for the selector
- XPathResolutionError - XPath does not resolve in the current page or frames
- StagehandShadowRootMissingError - No shadow root present on the resolved host element
- LLMResponseError - Error in LLM response processing
- MissingLLMConfigurationError - No LLM API key or client configured
- UnsupportedModelError - The specified model is not supported for this operation
- InvalidAISDKModelFormatError - Model string does not follow the required
provider/modelformat

