> ## Documentation Index
> Fetch the complete documentation index at: https://piyushvyas.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions, Tabs & Frames

> Manage browser sessions, tabs, and frames. Named sessions persist across CLI invocations.

# Sessions, Tabs & Frames

## Sessions

BAP browser pages persist across CLI invocations. When a client disconnects, the server parks the browser context. On reconnect with the same session ID, state is restored.

### Named Sessions

Use the `-s` flag to create and reuse named sessions:

```bash theme={null}
bap -s=checkout goto https://shop.example.com
bap -s=checkout act fill:label:"Search"="headphones" press:Enter
bap -s=checkout screenshot
```

All three commands operate on the same browser session. Without `-s`, the default session ID is `cli-<port>` (e.g., `cli-9222`).

### List Sessions

```bash theme={null}
bap sessions
```

Shows all active sessions with page counts.

<ParamField path="-s" type="string">
  Named session identifier. Commands with the same `-s` value share a browser context.
</ParamField>

<Note>
  Dormant sessions expire after 5 minutes (300 seconds) by default. After expiry, a new browser
  context is created on next use.
</Note>

## Tabs

### List Open Tabs

```bash theme={null}
bap tabs
```

### Open a New Tab

```bash theme={null}
bap tab-new
bap tab-new https://example.com
```

### Switch to a Tab

```bash theme={null}
bap tab-select 2
```

<ParamField path="index" type="number" required>
  Tab index (1-based) from the `bap tabs` output.
</ParamField>

### Close a Tab

```bash theme={null}
bap tab-close
```

Closes the currently active tab.

## Frames

For pages with iframes, use frame commands to switch context.

### List Frames

```bash theme={null}
bap frames
```

Shows all frames in the current page with their IDs.

### Switch to a Frame

```bash theme={null}
bap frame-switch <id>
```

<ParamField path="id" type="string" required>
  Frame ID from the `bap frames` output.
</ParamField>

After switching, all subsequent commands (click, fill, observe, etc.) operate within the selected frame.

<Tip>
  After switching to a frame, remember to switch back to the main frame when done. Use `bap frames`
  to see available frames and their IDs.
</Tip>

## Multi-Session Workflows

Run parallel workflows in separate sessions:

```bash theme={null}
# Terminal 1: Shopping flow
bap -s=shop goto https://shop.example.com

# Terminal 2: Admin panel
bap -s=admin goto https://admin.example.com

# Each session has its own browser context, cookies, and state
```
