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

type: 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.

JSON
// 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

type: next_tab

Switches focus to the next tab (higher index). Does nothing if already on the last tab.

JSON
{ "type": "next_tab" }

prev_tab

type: prev_tab

Switches focus to the previous tab (lower index). Does nothing if already on the first tab.

JSON
{ "type": "prev_tab" }

close_current_tab

type: 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.

JSON
{ "type": "close_current_tab" }

close_next_tab

type: 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.

JSON
{ "type": "close_next_tab" }

close_other_tabs

type: 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.

JSON
{ "type": "close_other_tabs" }

switch_to_tab

type: 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.

ParamTypeDescription
indexoptionalnumberZero-based tab index. Default: 0.
JSON
// Switch to the first tab
{ "type": "switch_to_tab", "index": 0 }

68
{ "type": "switch_to_tab", "index": 2 }

ensure_main_tab

type: 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.

JSON
{ "type": "ensure_main_tab" }