Skip to main content
POST
/
boxes
/
{boxId}
/
browser
/
tabs
/
{tabId}
/
switch
JavaScript
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();
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()
curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/browser/tabs/{tabId}/switch \
--header 'Authorization: Bearer <token>'
{
  "id": "1",
  "title": "Google",
  "url": "https://www.google.com",
  "favicon": "https://www.google.com/favicon.ico",
  "active": true,
  "loading": false
}

Authorizations

Authorization
string
header
required

Enter your API Key in the format: Bearer . Get it from https://gbox.ai

Path Parameters

boxId
string
required

Box ID

Example:

"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"

tabId
string
required

Response

200 - application/json

Successfully switched to the tab

Browser tab

id
string
required

The tab id

Example:

"1"

title
string
required

The tab title

Example:

"Google"

url
string
required

The tab url

Example:

"https://www.google.com"

favicon
string
required

The tab favicon

Example:

"https://www.google.com/favicon.ico"

active
boolean
required

Whether the tab is the current active (frontmost) tab

Example:

true

loading
boolean
required

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