> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/vercel-labs/agent-browser/llms.txt
> Use this file to discover all available pages before exploring further.

# Waiting Commands

> Wait for elements, conditions, and page states

## Overview

Waiting commands allow you to pause execution until specific conditions are met, ensuring reliable automation.

## wait

Wait for various conditions to be met.

### Wait for Element

Wait for an element to be visible.

<table>
  <thead>
    <tr>
      <th>Parameter</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>selector</code></td>
      <td>Element selector to wait for</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for element by ref
agent-browser wait @e1

# Wait for element by selector
agent-browser wait "#submit-button"

# Wait for element by text
agent-browser wait "text=Welcome"
```

### Wait for Time

Wait for a specific duration.

<table>
  <thead>
    <tr>
      <th>Parameter</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>milliseconds</code></td>
      <td>Time to wait in milliseconds</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait 1 second
agent-browser wait 1000

# Wait 5 seconds
agent-browser wait 5000
```

### Wait for Text

Wait for text to appear on the page.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>--text, -t</code></td>
      <td>Text to wait for</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for specific text
agent-browser wait --text "Welcome"

# Wait for success message
agent-browser wait -t "Form submitted successfully"
```

### Wait for URL

Wait for URL to match a pattern.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>--url, -u</code></td>
      <td>URL pattern to wait for (glob pattern)</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for URL containing "dashboard"
agent-browser wait --url "**/dashboard"

# Wait for URL ending with "success"
agent-browser wait -u "**/success"

# Wait for specific URL
agent-browser wait --url "https://example.com/done"
```

### Wait for Load State

Wait for page to reach a specific load state.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>--load, -l</code></td>
      <td>Load state: <code>load</code>, <code>domcontentloaded</code>, <code>networkidle</code></td>
    </tr>
  </tbody>
</table>

**Load States:**

<table>
  <thead>
    <tr>
      <th>State</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>load</code></td>
      <td>Page load event fired</td>
    </tr>

    <tr>
      <td><code>domcontentloaded</code></td>
      <td>DOM is fully loaded</td>
    </tr>

    <tr>
      <td><code>networkidle</code></td>
      <td>No network activity for 500ms</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for page load
agent-browser wait --load load

# Wait for DOM ready
agent-browser wait -l domcontentloaded

# Wait for network idle (recommended for SPAs)
agent-browser wait --load networkidle
```

### Wait for Function

Wait for JavaScript expression to return true.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>--fn, -f</code></td>
      <td>JavaScript expression to evaluate</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for custom condition
agent-browser wait --fn "window.ready === true"

# Wait for element count
agent-browser wait -f "document.querySelectorAll('.item').length > 0"

# Wait for global variable
agent-browser wait --fn "window.dataLoaded"
```

### Wait for Download

Wait for a file download to complete.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>--download, -d</code></td>
      <td>Wait for download</td>
    </tr>

    <tr>
      <td><code>path</code></td>
      <td>Optional: Save download to specific path</td>
    </tr>

    <tr>
      <td><code>--timeout</code></td>
      <td>Optional: Download timeout in milliseconds</td>
    </tr>
  </tbody>
</table>

**Examples:**

```bash theme={null}
# Wait for download
agent-browser wait --download

# Wait for download and save to path
agent-browser wait -d "/path/to/file.pdf"

# Wait with custom timeout
agent-browser wait --download --timeout 30000
```

## Workflow Examples

### Wait After Navigation

```bash theme={null}
# Navigate to page
agent-browser open example.com

# Wait for page to fully load
agent-browser wait --load networkidle

# Get snapshot
agent-browser snapshot -i
```

### Wait for Dynamic Content

```bash theme={null}
# Click button that loads content
agent-browser click @e1

# Wait for content to appear
agent-browser wait ".results"

# Or wait for specific text
agent-browser wait --text "Results loaded"
```

### Wait for Form Submission

```bash theme={null}
# Submit form
agent-browser click @e5

# Wait for URL change
agent-browser wait --url "**/success"

# Verify success message
agent-browser get text @e1
```

### Wait for AJAX Request

```bash theme={null}
# Trigger AJAX request
agent-browser click @e2

# Wait for network to be idle
agent-browser wait --load networkidle

# Or wait for specific condition
agent-browser wait --fn "window.ajaxComplete === true"
```

### Download File

```bash theme={null}
# Click download button
agent-browser click @e3

# Wait for download to complete
agent-browser wait --download "/path/to/downloads/file.pdf"
```

### Chained Waits

```bash theme={null}
# Navigate and wait
agent-browser open example.com && agent-browser wait --load networkidle

# Click and wait for element
agent-browser click @e1 && agent-browser wait @e2

# Wait for multiple conditions
agent-browser wait --load networkidle && agent-browser wait --text "Ready"
```

## Timeout Handling

The default timeout for wait commands is 25 seconds. Override with the `AGENT_BROWSER_DEFAULT_TIMEOUT` environment variable:

```bash theme={null}
# Set 45-second timeout
export AGENT_BROWSER_DEFAULT_TIMEOUT=45000
agent-browser wait --load networkidle
```

## Best Practices

### Use Network Idle for SPAs

```bash theme={null}
# After navigation, wait for network idle
agent-browser open app.example.com
agent-browser wait --load networkidle
```

### Wait for Specific Elements

```bash theme={null}
# Better than time-based waits
agent-browser wait ".content-loaded"
# Instead of:
# agent-browser wait 3000
```

### Combine Waits

```bash theme={null}
# Wait for load state first
agent-browser wait --load networkidle

# Then wait for specific element
agent-browser wait @e1
```
