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

# Switch to browser tab

> Switch to a specific browser tab by bringing it to the foreground (making it the active/frontmost tab). This operation sets the specified tab as the currently active tab without changing its URL or content. The tab will receive focus and become visible to the user. This is useful for managing multiple browser sessions and controlling which tab is currently in focus.



## OpenAPI

````yaml post /boxes/{boxId}/browser/tabs/{tabId}/switch
openapi: 3.0.0
info:
  title: GBOX Open API
  description: GBOX Open API Documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://gbox.ai/api/v1
    description: Production Server
security: []
tags: []
paths:
  /boxes/{boxId}/browser/tabs/{tabId}/switch:
    post:
      tags:
        - Browser
      summary: Switch to browser tab
      description: >-
        Switch to a specific browser tab by bringing it to the foreground
        (making it the active/frontmost tab). This operation sets the specified
        tab as the currently active tab without changing its URL or content. The
        tab will receive focus and become visible to the user. This is useful
        for managing multiple browser sessions and controlling which tab is
        currently in focus.
      operationId: BrowserController_switchTab
      parameters:
        - name: boxId
          required: true
          in: path
          description: Box ID
          schema:
            example: c9bdc193-b54b-4ddb-a035-5ac0c598d32d
            type: string
        - name: tabId
          required: true
          in: path
          schema:
            type: string
      responses:
        '200':
          description: Successfully switched to the tab
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BrowserTab'
      security:
        - bearer: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import GboxSDK from "gbox-sdk";

            const gboxSDK = new GboxSDK({
              apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
            });

            async function main() {
              const box = await gboxSDK.create({ type: "linux" });

              // First, open some tabs
              await box.browser.openTab("https://gbox.ai")
              await box.browser.openTab("https://gru.ai")
              await box.browser.openTab("https://google.com")

              // List tabs
              const tabsResult = await box.browser.listTabs();
              console.log("Available tabs:");
              for (const tab of tabsResult) {
                console.log(`  Tab ${tab.data.id}: ${tab.data.title} - Active: ${tab.data.active}`);
              }

              // Switch to first tab (make it the frontmost/active tab)
              const targetTab = tabsResult[0]

              const switchedTab = await box.browser.switchTab(targetTab.data.id);

              console.log(`Switched to tab successfully:`);
              console.log(`  ID: ${switchedTab.id}`);
              console.log(`  Title: ${switchedTab.title}`);
              console.log(`  URL: ${switchedTab.url}`);
              console.log(`  Active: ${switchedTab.active}`);

              // Verify the switch by listing tabs again
              const updatedTabsResult = await box.browser.listTabs();
              console.log("\nTabs after switching:");
              for (const tab of updatedTabsResult) {
                console.log(`  Tab ${tab.data.id}: ${tab.data.title} - Active: ${tab.data.active}`);
              }
            }

            main();
        - lang: Python
          source: |-
            import os
            from gbox_sdk import GboxSDK

            def main():
                gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])

                box = gbox_sdk.create(type="linux")

                # First, open some tabs
                box.browser.open_tab("https://gbox.ai")
                box.browser.open_tab("https://gru.ai")
                box.browser.open_tab("https://google.com")

                # List tabs
                tabs_result = box.browser.list_tabs()
                print("Available tabs:")
                for tab in tabs_result:
                    print(f"  Tab {tab.data.id}: {tab.data.title} - Active: {tab.data.active}")

                # Switch to first tab (make it the frontmost/active tab)
                target_tab = tabs_result[0]

                switched_tab = box.browser.switch_tab(target_tab.data.id)

                print(f"Switched to tab successfully:")
                print(f"  ID: {switched_tab.id}")
                print(f"  Title: {switched_tab.title}")
                print(f"  URL: {switched_tab.url}")
                print(f"  Active: {switched_tab.active}")

                # Verify the switch by listing tabs again
                updated_tabs_result = box.browser.list_tabs()
                print("\nTabs after switching:")
                for tab in updated_tabs_result:
                    print(f"  Tab {tab.data.id}: {tab.data.title} - Active: {tab.data.active}")

            if __name__ == "__main__":
                main()
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/gbox/gbox-sdk-go\"\n)\n\nfunc main() {\n\tgboxSDK := gbox.NewGboxSDK(os.Getenv(\"GBOX_API_KEY\"))\n\n\tbox, err := gboxSDK.Create(context.Background(), gbox.CreateOptions{Type: \"linux\"})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create linux box: %v\", err)\n\t}\n\n\t// First, open some tabs\n\terr = box.Browser.OpenTab(context.Background(), \"https://gbox.ai\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to open tab: %v\", err)\n\t}\n\n\terr = box.Browser.OpenTab(context.Background(), \"https://gru.ai\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to open tab: %v\", err)\n\t}\n\n\terr = box.Browser.OpenTab(context.Background(), \"https://google.com\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to open tab: %v\", err)\n\t}\n\n\t// List tabs\n\ttabsResult, err := box.Browser.ListTabs(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to list browser tabs: %v\", err)\n\t}\n\n\tfmt.Println(\"Available tabs:\")\n\tfor _, tab := range tabsResult {\n\t\tfmt.Printf(\"  Tab %s: %s - Active: %t\\n\", tab.Data.ID, tab.Data.Title, tab.Data.Active)\n\t}\n\n\t// Switch to first tab (make it the frontmost/active tab)\n\ttargetTab := tabsResult[0]\n\n\tswitchedTab, err := box.Browser.SwitchTab(context.Background(), targetTab.Data.ID)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to switch tab: %v\", err)\n\t}\n\n\tfmt.Printf(\"Switched to tab successfully:\\n\")\n\tfmt.Printf(\"  ID: %s\\n\", switchedTab.ID)\n\tfmt.Printf(\"  Title: %s\\n\", switchedTab.Title)\n\tfmt.Printf(\"  URL: %s\\n\", switchedTab.URL)\n\tfmt.Printf(\"  Active: %t\\n\", switchedTab.Active)\n\n\t// Verify the switch by listing tabs again\n\tupdatedTabsResult, err := box.Browser.ListTabs(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to list updated browser tabs: %v\", err)\n\t}\n\n\tfmt.Println(\"\\nTabs after switching:\")\n\tfor _, tab := range updatedTabsResult {\n\t\tfmt.Printf(\"  Tab %s: %s - Active: %t\\n\", tab.Data.ID, tab.Data.Title, tab.Data.Active)\n\t}\n}"
components:
  schemas:
    BrowserTab:
      type: object
      properties:
        id:
          type: string
          description: The tab id
          example: '1'
          title: TabId
        title:
          type: string
          description: The tab title
          example: Google
          title: TabTitle
        url:
          type: string
          description: The tab url
          example: https://www.google.com
          title: TabUrl
        favicon:
          type: string
          description: The tab favicon
          example: https://www.google.com/favicon.ico
          title: TabFavicon
        active:
          type: boolean
          description: Whether the tab is the current active (frontmost) tab
          example: true
          title: TabActive
        loading:
          type: boolean
          description: >-
            Whether the tab is currently in a loading state.


            The value is **true** while the browser is still navigating to the
            target URL or fetching sub-resources (i.e. `document.readyState` is
            not "complete"). It typically switches to **false** once the `load`
            event fires and all major network activity has settled.
          example: false
          title: TabLoading
      title: Browser Tab
      description: Browser tab
      required:
        - id
        - title
        - url
        - favicon
        - active
        - loading
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: >-
        Enter your API Key in the format: Bearer <token>. Get it from
        https://gbox.ai

````