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. The high-level wrapper methods (computer.navigate(), computer.click(), etc.) don’t expose this parameter directly. Use computer.execute() for tab-specific operations:
from tzafon import Computer

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

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

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

    result = computer.execute({
        "type": "screenshot",
        "tab_id": "tab_abc123"
    })
Important: The high-level wrapper methods (computer.navigate(), computer.click(), etc.) do NOT support the tab_id parameter. Use computer.execute() for tab-specific operations.
If tab_id is not specified, actions execute on the currently active tab.

Dedicated Tabs API

The TypeScript SDK exposes tab endpoints via client.computers.tabs:
TypeScript
import Computer from '@tzafon/computer';

const client = new Computer();
const computer = await client.create({ kind: 'browser' });

const computerId = computer.id;

// List all tabs
const result = await client.computers.tabs.list(computerId);
const tabs = result.result.tabs;  // array of tab objects with tab_id, url, is_main

// Create a new tab
const createResult = await client.computers.tabs.create(computerId, { url: 'https://example.com' });
const tabId = createResult.result.created_tab_id;

// Switch to a tab
await client.computers.tabs.switch(tabId, computerId);

// Close/delete a tab
await client.computers.tabs.delete(tabId, computerId);

await computer.terminate();

Tab Management Methods

List Tabs

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

for tab in result.result["tabs"]:
    print(f"Tab {tab['tab_id']}: {tab['url']} (main: {tab['is_main']})")
Returns:
  • ActionResult with result["tabs"] array containing tab objects with tab_id, url, is_main fields

Create Tab

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

tab_id = result.result["created_tab_id"]
print(f"Created tab: {tab_id}")
Parameters:
  • computer_id (string) - ID of the computer session
  • url (string, optional) - URL to navigate the new tab to
Returns:
  • ActionResult with result["created_tab_id"] containing the new tab’s ID

Switch Tab

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

Delete Tab

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

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:
    # Navigate the initial tab
    computer.navigate("https://wikipedia.org")
    computer.wait(2)

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

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

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

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

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

    # Take screenshots of both tabs
    screenshot1 = computer.execute({"type": "screenshot", "tab_id": main_tab})
    screenshot2 = computer.execute({"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({
        "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 client.computers.tabs.list() 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