Playwright is a browser automation library that allows you to automate browser actions.

Gbox provides scalable, cloud-based remote environments for Playwright automation. Instead of running browsers locally, Gbox spins up isolated browser instances in the cloud that you can control remotely through Playwright’s API. This enables you to:

  • Scale your automation - Run multiple Playwright tests in parallel without hardware limitations
  • Consistent environments - Execute tests in standardized browser environments, eliminating “works on my machine” issues
  • Resource efficiency - Offload browser processes to the cloud, freeing up local resources
  • Cross-platform testing - Access different operating systems and browser versions without local setup
  • Remote debugging - Debug and inspect automated browser sessions through live view capabilities

With Gbox’s remote browser environments, your Playwright scripts gain enterprise-grade scalability and reliability while maintaining the same familiar API you’re used to.

1

Get an API Key

  1. Go to Gbox AI
  2. Copy your API Key
  3. Paste your Gbox API Key into your env file
.env
GBOX_API_KEY=gbox-******
2

Install Gbox SDK and other dependencies

Install gbox-sdk and other dependencies by running the following command in your terminal.

npm install gbox-sdk dotenv typescript tsx playwright @types/node
3

Create a new Playwright test

Create a new Playwright test by running the following code.

import GboxSDK from "gbox-sdk";
import { chromium } from "playwright";
import * as dotenv from "dotenv";

dotenv.config();

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" });

  console.log(`Box created: ${box.data.id}`);

  // 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://gbox.ai");

  // Take a screenshot of the page
  await page.screenshot({ path: "screenshot.png" });

  // Perform actions on the page
  console.log(await page.title());

  // Close the browser
  await browser.close();
  console.log("Browser closed");

  // Terminate the box
  await box.terminate();

  console.log("Box terminated");
}

main();
4

Run the test

Run the test by running the following command in your terminal.

npx tsx index.ts