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, let's list tabs to see what we have
  const tabsResult = await box.browser.listTabs();
  console.log("Available tabs:");
  for (const tab of tabsResult.tabs) {
    console.log(`  Tab ${tab.id}: ${tab.title} - Active: ${tab.active}`);
  }

  // Switch to tab 2 (make it the frontmost/active tab)
  const switchedTab = await box.browser.switchTab("2");

  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.tabs) {
    console.log(`  Tab ${tab.id}: ${tab.title} - Active: ${tab.active}`);
  }
}

main();
{
  "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 <token>. 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