Tab Management
Actions for managing browser tabs within an automation session. The engine tracks all open tabs by their context. Tab indexes are dynamic — closing a tab shifts higher indexes down by one.
auto_switch_new_tab
Installs a persistent listener that automatically switches focus to any newly opened tab. Once set, every new tab that opens (from link clicks, popups, etc.) is automatically brought to front. The listener stays active for the rest of the session — you only need to call this once.
// Install the auto-switch listener, then click a link that opens a new tab
{ "type": "auto_switch_new_tab" }
{ "type": "click", "selector": "a.external-link" }next_tab
Switches focus to the next tab (higher index). Does nothing if already on the last tab.
{ "type": "next_tab" }prev_tab
Switches focus to the previous tab (lower index). Does nothing if already on the first tab.
{ "type": "prev_tab" }close_current_tab
Closes the currently focused tab and switches to the previous one (by index). If only one tab remains, it stays open — the engine never closes the last tab.
{ "type": "close_current_tab" }close_next_tab
Closes the tab immediately after the current one (by index) without switching away. Useful for dismissing a popup tab that opened in the background.
{ "type": "close_next_tab" }close_other_tabs
Closes every tab except the currently focused one. Good for cleanup after a multi-tab workflow or when popups have spawned unwanted tabs.
{ "type": "close_other_tabs" }switch_to_tab
Switches focus to a specific tab by its zero-based index. Tab 0 is the original (first) tab. Does nothing if the index doesn't exist.
| Param | Type | Description |
|---|---|---|
| indexoptional | number | Zero-based tab index. Default: 0. |
// Switch to the first tab
{ "type": "switch_to_tab", "index": 0 }
68
{ "type": "switch_to_tab", "index": 2 }ensure_main_tab
Switches back to the first (main) tab. A shorthand for switch_to_tab with index 0. Does not close other tabs — use close_other_tabs first if you want cleanup.
{ "type": "ensure_main_tab" }