> ## 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:

<CodeGroup>
  ```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
  ```
</CodeGroup>

## Basic Connection

Connect Playwright to a Hyperbrowser session:

<CodeGroup>
  ```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()
  ```
</CodeGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Puppeteer Integration" icon="node" href="/sessions/puppeteer">
    Connect with Puppeteer
  </Card>

  <Card title="Session Lifecycle" icon="rotate" href="/sessions/lifecycle">
    Manage sessions
  </Card>

  <Card title="Stealth Mode" icon="user-secret" href="/sessions/stealth">
    Configure anti-detection
  </Card>

  <Card title="Profiles" icon="user" href="/sessions/profiles">
    Persist browser state
  </Card>
</CardGroup>
