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

# Connect with Playwright

> Control Hyperbrowser sessions using Playwright

Playwright is a powerful browser automation framework that works seamlessly with Hyperbrowser sessions. This guide shows you how to connect Playwright to your cloud browser sessions.

## Installation

First, install Playwright:

```bash npm theme={null}
npm install @hyperbrowser/sdk playwright-core dotenv
```

```bash yarn theme={null}
yarn add @hyperbrowser/sdk playwright-core dotenv
```

```bash pip theme={null}
pip install hyperbrowser playwright python-dotenv
```

```bash uv theme={null}
uv add hyperbrowser playwright python-dotenv
```

## Basic Connection

Connect Playwright to a Hyperbrowser session:

```typescript Node.js theme={null}
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { chromium } from "playwright-core";
import { config } from "dotenv";

config();

const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});

async function main() {
  // Create session
  const session = await client.sessions.create({
    acceptCookies: true,
  });

  try {
    // Connect Playwright
    const browser = await chromium.connectOverCDP(session.wsEndpoint);
    const defaultContext = browser.contexts()[0];

    // Get the default page
    const page = defaultContext.pages()[0];

    // Navigate and interact
    await page.goto("https://example.com");
    console.log("Title:", await page.title());
  } catch (err) {
    console.error("Encountered error:", err);
  } finally {
    // Clean up
    await client.sessions.stop(session.id);
  }
}

main().catch(console.error);
```

```python Python theme={null}
from hyperbrowser import Hyperbrowser
from playwright.sync_api import sync_playwright
import os
from dotenv import load_dotenv

load_dotenv()

client = Hyperbrowser(api_key=os.environ["HYPERBROWSER_API_KEY"])


def main():
    # Create session
    session = client.sessions.create()

    try:
        with sync_playwright() as p:
            # Connect Playwright
            browser = p.chromium.connect_over_cdp(session.ws_endpoint)
            default_context = browser.contexts[0]

            # Get the default page
            page = default_context.pages[0]

            # Navigate and interact
            page.goto("https://example.com")
            print(f"Title: {page.title()}")

    except Exception as e:
        print(f"Encountered error: {e}")
    finally:
        # Clean up
        client.sessions.stop(session.id)


main()
```

## Next Steps

> **[Puppeteer Integration](/docs/sessions/puppeteer)**
>
> Connect with Puppeteer

> **[Session Lifecycle](/docs/sessions/lifecycle)**
>
> Manage sessions

> **[Stealth Mode](/docs/sessions/stealth)**
>
> Configure anti-detection

> **[Profiles](/docs/sessions/profiles)**
>
> Persist browser state


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.