Skip to main content

Overview

Browser sessions support multi-tab management, allowing you to open, switch between, and control multiple tabs within a single computer instance. This enables complex workflows like:
  • Comparing content across multiple pages
  • Filling forms on different sites simultaneously
  • Monitoring multiple dashboards
  • Cross-tab automation workflows
Multi-tab management is browser sessions only. Desktop instances do not support tabs.

Tab-Aware Actions

All browser actions support targeting specific tabs using the tab_id parameter. However, the high-level wrapper methods don’t expose this parameter directly. You must use the direct API or the execute_action()/execute() method:
from tzafon import Computer

client = Computer()
with client.create(kind="browser") as computer:
    # METHOD 1: Use execute_action for tab-specific operations
    computer.execute_action({
        "type": "navigate",
        "url": "https://example.com",
        "tab_id": "tab_abc123"
    })

    computer.execute_action({
        "type": "click",
        "x": 100,
        "y": 200,
        "tab_id": "tab_abc123"
    })

    computer.execute_action({
        "type": "type",
        "text": "Hello",
        "tab_id": "tab_abc123"
    })

    result = computer.execute_action({
        "type": "screenshot",
        "tab_id": "tab_abc123"
    })

    # METHOD 2: Use the direct API (via client.computers)
    client.computers.navigate(
        computer.id,
        url="https://example.com",
        tab_id="tab_abc123"
    )

    client.computers.click(
        computer.id,
        x=100,
        y=200,
        tab_id="tab_abc123"
    )
Important: The high-level wrapper methods (computer.navigate(), computer.click(), etc.) do NOT support the tab_id parameter. Use execute_action()/execute() or the direct client.computers.* API for tab-specific operations.
If tab_id is not specified, actions execute on the currently active tab.

Tab Management Actions

List Tabs

Get all open tabs in the current browser session:
result = computer.execute_action({
    "type": "list_tabs"
})

tabs = result.result['tabs']
for tab in tabs:
    print(f"Tab {tab['id']}: {tab['title']} - {tab['url']}")
Returns:
  • Array of tab objects with id, title, url, is_active

New Tab

Create a new browser tab:
result = computer.execute_action({
    "type": "new_tab",
    "url": "https://example.com"  # Optional
})

new_tab_id = result.executed_tab_id
print(f"Created tab: {new_tab_id}")
Parameters:
  • url (string, optional) - URL to navigate the new tab to
Returns:
  • executed_tab_id contains the new tab’s ID

Switch Tab

Change the active tab:
computer.execute_action({
    "type": "switch_tab",
    "tab_id": "tab_abc123"
})
Parameters:
  • tab_id (string) - ID of the tab to switch to

Close Tab

Close a specific tab:
computer.execute_action({
    "type": "close_tab",
    "tab_id": "tab_abc123"
})
Parameters:
  • tab_id (string) - ID of the tab to close

Complete Multi-Tab Example

Here’s a complete workflow using multiple tabs:
from tzafon import Computer

client = Computer()
with client.create(kind="browser") as computer:
    # Create first tab and navigate
    computer.navigate("https://wikipedia.org")
    computer.wait(2)

    # List tabs to get the main tab ID
    result = computer.execute_action({"type": "list_tabs"})
    main_tab = result.result['tabs'][0]['id']

    # Create a second tab
    result = computer.execute_action({
        "type": "new_tab",
        "url": "https://example.com"
    })
    second_tab = result.executed_tab_id

    # Work on second tab using execute_action
    computer.execute_action({
        "type": "click",
        "x": 100,
        "y": 200,
        "tab_id": second_tab
    })
    computer.execute_action({
        "type": "type",
        "text": "search query",
        "tab_id": second_tab
    })

    # Switch back to main tab
    computer.execute_action({
        "type": "switch_tab",
        "tab_id": main_tab
    })

    # Work on main tab
    computer.execute_action({
        "type": "click",
        "x": 150,
        "y": 250,
        "tab_id": main_tab
    })

    # Take screenshots of both tabs
    screenshot1 = computer.execute_action({
        "type": "screenshot",
        "tab_id": main_tab
    })
    screenshot2 = computer.execute_action({
        "type": "screenshot",
        "tab_id": second_tab
    })

    print(f"Tab 1: {screenshot1.result['screenshot_url']}")
    print(f"Tab 2: {screenshot2.result['screenshot_url']}")

    # Close the second tab
    computer.execute_action({
        "type": "close_tab",
        "tab_id": second_tab
    })

Use Cases

Open tabs for multiple websites, fill forms on each, and submit them in sequence or parallel.
Compare prices, features, or content across multiple e-commerce sites or product pages.
Monitor multiple dashboards simultaneously, taking periodic screenshots of each.
Copy data from one tab, switch to another tab, and paste it - automating cross-site workflows.

Best Practices

Track your tab IDs carefully. Store tab IDs in variables to avoid confusion when managing multiple tabs. Executing actions on the wrong tab is a common mistake.
Use list_tabs periodically to verify which tabs are still open and get their current state.
Always close tabs you no longer need to free up browser resources. Each tab consumes memory and CPU.

Next Steps