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
}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.
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
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Response
Successfully switched to the tab
Browser tab
The tab id
"1"
The tab title
"Google"
The tab url
"https://www.google.com"
The tab favicon
"https://www.google.com/favicon.ico"
Whether the tab is the current active (frontmost) tab
true
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.
false
Was this page helpful?