> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gbox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Playwright with GBOX

[Playwright](https://playwright.dev/) 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.

<Steps>
  <Step title="Get an API Key">
    1. Go to [GBOX AI](http://gbox.ai)
    2. Copy your API Key
    3. Paste your GBOX API Key into your `env` file

    ```bash .env theme={null}
    GBOX_API_KEY=gbox-******
    ```
  </Step>

  <Step title="Install GBOX SDK and other dependencies">
    Install gbox-sdk and other dependencies by running the following command in your terminal.

    <CodeGroup>
      ```bash TypeScript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null}
      npm install gbox-sdk dotenv typescript tsx playwright @types/node
      ```

      ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null}
      # Set up a virtual environment
      python3 -m venv venv
      source venv/bin/activate

      pip install gbox-sdk python-dotenv playwright
      ```
    </CodeGroup>
  </Step>

  <Step title="Create a new Playwright test">
    Create a new Playwright test by running the following code.

    <CodeGroup>
      ```typescript TypeScript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" highlight={17} theme={null}
      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();
      ```

      ```python Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" highlight={19} theme={null}
      import os
      from dotenv import load_dotenv
      from gbox_sdk import GboxSDK
      from playwright.sync_api import sync_playwright

      # Load environment variables from .env file
      load_dotenv()

      def main():
          api_key = os.getenv("GBOX_API_KEY")

          gbox = GboxSDK(api_key=api_key)

          box = gbox.create(type="linux")

          print(f"Box created: {box.data.id}")

          # Get browser CDP URL for Chrome DevTools Protocol connection
          cdp_url = box.browser.cdp_url()

          print(f"Browser CDP URL: {cdp_url}")

          with sync_playwright() as p:
              browser = p.chromium.connect_over_cdp(cdp_url)

              # Use the browser as usual
              context = browser.new_context()
              page = context.new_page()
              page.goto("https://gbox.ai")

              # Take a screenshot of the page
              page.screenshot(path="screenshot.png")

              # Perform actions on the page
              print(page.title())

              # Close the browser
              browser.close()
              print("Browser closed")

          # Terminate the box
          box.terminate()

          print("Box terminated")

      if __name__ == "__main__":
          main()
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the test">
    Run the test by running the following command in your terminal.

    <CodeGroup>
      ```bash TypeScript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null}
      npx tsx index.ts
      ```

      ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null}
      python main.py
      ```
    </CodeGroup>
  </Step>
</Steps>
