# Stagehand Blocks

Blocks for AI-powered browser automation using Stagehand and Browserbase.

## Stagehand Act

### What it is

Interact with a web page by performing actions on a web page. Use it to build self-healing and deterministic automations that adapt to website chang.

### How it works

This block uses Stagehand with Browserbase to perform web actions using AI-powered element detection. Actions like click, fill, type, scroll, and select are described in natural language and executed reliably even if the page structure changes.

Configure timeouts for DOM settlement and page loading. Variables can be passed to actions for dynamic data entry.

### Inputs

| Input                    | Description                                                                                                                                           | Type                                                                              | Required |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | -------- |
| browserbase\_project\_id | Browserbase project ID (required if using Browserbase)                                                                                                | str                                                                               | Yes      |
| model                    | LLM to use for Stagehand (provider is inferred)                                                                                                       | "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "claude-3-7-sonnet-20250219" | No       |
| url                      | URL to navigate to.                                                                                                                                   | str                                                                               | Yes      |
| action                   | Action to perform. Suggested actions are: click, fill, type, press, scroll, select from dropdown. For multi-step actions, add an entry for each step. | List\[str]                                                                        | Yes      |
| variables                | Variables to use in the action. Variables contains data you want the action to use.                                                                   | Dict\[str, str]                                                                   | No       |
| iframes                  | Whether to search within iframes. If True, Stagehand will search for actions within iframes.                                                          | bool                                                                              | No       |
| domSettleTimeoutMs       | Timeout in milliseconds for DOM settlement.Wait longer for dynamic content                                                                            | int                                                                               | No       |
| timeoutMs                | Timeout in milliseconds for DOM ready. Extended timeout for slow-loading forms                                                                        | int                                                                               | No       |

### Outputs

| Output  | Description                                   | Type |
| ------- | --------------------------------------------- | ---- |
| error   | Error message if the operation failed         | str  |
| success | Whether the action was completed successfully | bool |
| message | Details about the action’s execution.         | str  |
| action  | Action performed                              | str  |

### Possible use case

**Form Automation**: Fill out web forms, submit applications, or complete checkout flows.

**Self-Healing Scrapers**: Build automations that adapt to website changes without breaking.

**Testing Workflows**: Automate testing of web applications with resilient element targeting.

***

## Stagehand Extract

### What it is

Extract structured data from a webpage.

### How it works

This block uses Stagehand with Browserbase to extract data from web pages using natural language instructions. Describe what data you want to extract, and the AI identifies and returns the matching content.

Supports searching within iframes and configurable timeouts for dynamic content that loads after the initial page render.

### Inputs

| Input                    | Description                                                                                  | Type                                                                              | Required |
| ------------------------ | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | -------- |
| browserbase\_project\_id | Browserbase project ID (required if using Browserbase)                                       | str                                                                               | Yes      |
| model                    | LLM to use for Stagehand (provider is inferred)                                              | "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "claude-3-7-sonnet-20250219" | No       |
| url                      | URL to navigate to.                                                                          | str                                                                               | Yes      |
| instruction              | Natural language description of elements or actions to discover.                             | str                                                                               | Yes      |
| iframes                  | Whether to search within iframes. If True, Stagehand will search for actions within iframes. | bool                                                                              | No       |
| domSettleTimeoutMs       | Timeout in milliseconds for DOM settlement.Wait longer for dynamic content                   | int                                                                               | No       |

### Outputs

| Output     | Description                           | Type |
| ---------- | ------------------------------------- | ---- |
| error      | Error message if the operation failed | str  |
| extraction | Extracted data from the page.         | str  |

### Possible use case

**Data Scraping**: Extract product details, prices, or contact information from websites.

**Competitive Intelligence**: Pull data from competitor pages for analysis and monitoring.

**Research Automation**: Gather information from multiple web sources for research workflows.

***

## Stagehand Observe

### What it is

Find suggested actions for your workflows

### How it works

This block analyzes a web page to discover available actions based on natural language instructions. It returns XPath selectors, action methods, and descriptions for elements matching your query.

Use this to explore a page's interactive elements before building automated workflows.

### Inputs

| Input                    | Description                                                                                  | Type                                                                              | Required |
| ------------------------ | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | -------- |
| browserbase\_project\_id | Browserbase project ID (required if using Browserbase)                                       | str                                                                               | Yes      |
| model                    | LLM to use for Stagehand (provider is inferred)                                              | "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "claude-3-7-sonnet-20250219" | No       |
| url                      | URL to navigate to.                                                                          | str                                                                               | Yes      |
| instruction              | Natural language description of elements or actions to discover.                             | str                                                                               | Yes      |
| iframes                  | Whether to search within iframes. If True, Stagehand will search for actions within iframes. | bool                                                                              | No       |
| domSettleTimeoutMs       | Timeout in milliseconds for DOM settlement.Wait longer for dynamic content                   | int                                                                               | No       |

### Outputs

| Output      | Description                           | Type       |
| ----------- | ------------------------------------- | ---------- |
| error       | Error message if the operation failed | str        |
| selector    | XPath selector to locate element.     | str        |
| description | Human-readable description            | str        |
| method      | Suggested action method               | str        |
| arguments   | Additional action parameters          | List\[str] |

### Possible use case

**Workflow Discovery**: Identify available actions on a page before building automations.

**Dynamic Navigation**: Discover clickable elements for pages with changing layouts.

**Automation Development**: Build robust automation workflows by understanding page structure.

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://agpt.co/docs/integrations/block-integrations/blocks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
