Method Signatures
- TypeScript
Parameters
- Instruction: Natural language description of the action to perform. Use
%variableName%syntax to reference variables. - Action: A deterministic action to perform:
Configure the AI model to use for this action. Can be either:
- A string in the format
"provider/model"(e.g.,openai/gpt-5,google/gemini-2.5-flash) - An object with detailed configuration
Key-value pairs for variable substitution using
%variableName% syntax in your instruction. Variables are not shared with LLM providers, making them ideal for sensitive data like passwords and API keys.Example:Maximum time in milliseconds to wait for the action to complete. Default varies by configuration.
Optional: Specify which page to perform the action 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
Returns Promise<ActResult>
Whether the action completed successfully
Human-readable message describing the result
Instruction that was used to perform the action
Array of actions that were executed
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
- Variables
- Custom Model
- Multi-Page
- Caching
Error Types
The following errors may be thrown by theact() method:
- StagehandError - Base class for all Stagehand-specific errors
- StagehandElementNotFoundError - Target element could not be located using the provided selector(s)
- StagehandClickError - Failed to click on the target element
- StagehandEvalError - Error occurred while evaluating JavaScript in the page context
- StagehandDomProcessError - Error occurred while processing the DOM
- 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

