JavaScript
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" });
// Get browser CDP URL for Chrome DevTools Protocol connection
const cdpUrl = await box.browser.cdpUrl();
console.log(`Browser CDP URL: ${cdpUrl}`);
const browser = await chromium.connectOverCDP(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());
// Close the browser
await 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"])
# Create a new linux box
box = gbox_sdk.create(type="linux")
# Get browser CDP URL for Chrome DevTools Protocol connection
cdp_url = box.browser.cdp_url()
print(f"Browser CDP URL: {cdp_url}")
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(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()
if __name__ == "__main__":
asyncio.run(main())curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/browser/connect-url/cdp \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expiresIn": "120m"
}
'"https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/"Browser
Generate CDP url
This endpoint allows you to generate a pre-signed URL for accessing the Chrome DevTools Protocol (CDP) of a running box. The URL is valid for a limited time and can be used to interact with the box’s browser environment
POST
/
boxes
/
{boxId}
/
browser
/
connect-url
/
cdp
JavaScript
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" });
// Get browser CDP URL for Chrome DevTools Protocol connection
const cdpUrl = await box.browser.cdpUrl();
console.log(`Browser CDP URL: ${cdpUrl}`);
const browser = await chromium.connectOverCDP(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());
// Close the browser
await 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"])
# Create a new linux box
box = gbox_sdk.create(type="linux")
# Get browser CDP URL for Chrome DevTools Protocol connection
cdp_url = box.browser.cdp_url()
print(f"Browser CDP URL: {cdp_url}")
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(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()
if __name__ == "__main__":
asyncio.run(main())curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/browser/connect-url/cdp \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expiresIn": "120m"
}
'"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
Example:
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Body
application/json
Generate pre-signed CDP url
Generate cdp url
The CDP url will be alive for the given duration
Supported time units: ms (milliseconds), s (seconds), m (minutes), h (hours) Example formats: "500ms", "30s", "5m", "1h" Default: 120m
Example:
"120m"
Response
200 - application/json
Generate pre-signed CDP url
The response is of type string.
Example:
"https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/"
Was this page helpful?