import GboxSDK from "gbox-sdk";
import { chromium } from "playwright";
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" });
const result = await box.browser.open({
maximize: true,
showControls: false,
})
const browser = await chromium.connectOverCDP(result.cdpUrl);
// Use the browser as usual
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://example.com");
// Perform actions on the page
console.log(await page.title());
await box.browser.close()
}
main();import os
import asyncio
from gbox_sdk import GboxSDK
from playwright.async_api import async_playwright
async def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Open browser with configuration
result = await box.browser.open(
maximize=True,
showControls=False
)
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(result.cdp_url)
# Use the browser as usual
context = await browser.new_context()
page = await context.new_page()
await page.goto("https://example.com")
# Perform actions on the page
title = await page.title()
print(title)
# Close the browser
await browser.close()
await box.browser.close()
if __name__ == "__main__":
asyncio.run(main())curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/browser/open \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"showControls": true,
"maximize": false,
"size": "1024x768"
}
'{
"cdpUrl": "https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/"
}Open browser
Open the browser in the specified box. If the browser is already open, repeated calls will not open a new browser.
import GboxSDK from "gbox-sdk";
import { chromium } from "playwright";
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" });
const result = await box.browser.open({
maximize: true,
showControls: false,
})
const browser = await chromium.connectOverCDP(result.cdpUrl);
// Use the browser as usual
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://example.com");
// Perform actions on the page
console.log(await page.title());
await box.browser.close()
}
main();import os
import asyncio
from gbox_sdk import GboxSDK
from playwright.async_api import async_playwright
async def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Open browser with configuration
result = await box.browser.open(
maximize=True,
showControls=False
)
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(result.cdp_url)
# Use the browser as usual
context = await browser.new_context()
page = await context.new_page()
await page.goto("https://example.com")
# Perform actions on the page
title = await page.title()
print(title)
# Close the browser
await browser.close()
await box.browser.close()
if __name__ == "__main__":
asyncio.run(main())curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/browser/open \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"showControls": true,
"maximize": false,
"size": "1024x768"
}
'{
"cdpUrl": "https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/"
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Body
Browser open configuration
Browser open config
Whether to show the browser's minimize, maximize and close buttons. Default is true.
true
Whether to maximize the browser window.
false
The window size, format: x. If not specified, the browser will open with the default size. If both maximize and size are specified, maximize will take precedence.
"1024x768"
Response
Successfully opened the browser, return the CDP url
Browser open result
The CDP url. You can use this URL with CDP libraries like puppeteer/playwright/etc.
"https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/"
Was this page helpful?