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

# CDP Endpoint

> Connect to the browser session programmatically using a Chrome DevTools Protocol (CDP) endpoint.

To get started, you first need to create a Grasp container. This will provision a cloud environment with a browser instance ready for you to connect to.

## Creating a Container

Here is the basic setup for creating a container.

<CodeGroup>
  ```javascript JavaScript/TypeScript theme={null}
  import { Grasp } from '@getgrasp/sdk';

  // Make sure your GRASP_API_KEY is set as an environment variable
  const grasp = new Grasp();

  const container = await grasp.create();

  console.log('Container created with ID:', container.id);
  ```

  ```python Python theme={null}
  from grasp import Grasp

  # Make sure your GRASP_API_KEY is set as an environment variable
  grasp = Grasp()

  container = grasp.create()

  print(f"Container created with ID: {container.id}")
  ```
</CodeGroup>

Once the container is created, you can access its CDP endpoint to connect programmatically.

## Connecting with CDP

For powerful, programmatic control over the browser, Grasp exposes a Chrome DevTools Protocol (CDP) WebSocket endpoint. This allows you to connect with popular automation libraries like Playwright or Puppeteer.

<CodeGroup>
  ```javascript JavaScript/TypeScript theme={null}
  const wsEndpoint = container.browser.wsEndpoint;
  // Example: wss://9223-e8b3b6b2-2b8a-4c6b-a1b3-f1b3b6b2b8a4.grasp.run
  ```

  ```python Python theme={null}
  ws_endpoint = container.browser.ws_endpoint
  # Example: wss://9223-e8b3b6b2-2b8a-4c6b-a1b3-f1b3b6b2b8a4.grasp.run
  ```
</CodeGroup>

## Example with Playwright

Here's a complete example showing how to create a container and then connect to its browser session using Playwright.

<CodeGroup>
  ```javascript JavaScript/TypeScript theme={null}
  import { Grasp } from '@getgrasp/sdk';
  import { chromium } from 'playwright';

  const grasp = new Grasp();
  const container = await grasp.create();

  // Connect Playwright to the cloud browser via CDP
  const browser = await chromium.connectOverCDP(container.browser.wsEndpoint);

  const page = await browser.newPage();
  await page.goto('https://www.google.com');
  console.log('Page title:', await page.title());

  await browser.close();
  await container.shutdown();
  ```

  ```python Python theme={null}
  from grasp import Grasp
  from playwright.sync_api import sync_playwright

  # Initialize the Grasp client
  grasp = Grasp()

  # Create a new container
  container = grasp.create()

  # Connect Playwright to the cloud browser
  with sync_playwright() as p:
      browser = p.chromium.connect_over_cdp(container.browser.ws_endpoint)
      page = browser.new_page()
      page.goto("https://www.google.com")
      print(f"Page title: {page.title()}")
      browser.close()

  # Clean up
  container.shutdown()
  ```
</CodeGroup>

This enables you to run complex automation scripts, scrape data, or perform tests on the browser instance managed by Grasp.
