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

# Start your first session with Playwright

> Connect Playwright to Browserbase cloud browsers in minutes. Run headless browser automation at scale with session recording and debugging.

<CardGroup cols={2}>
  <Card title="Get started with a Playwright Node.js template" icon="rocket" iconType="sharp-solid" href="https://www.browserbase.com/templates/quickstart-playwright">
    Get started with Browserbase and Playwright in Node.js.
  </Card>

  <Card title="Get started with a Playwright Python template" icon="rocket" iconType="sharp-solid" href="https://www.browserbase.com/templates/quickstart-playwright">
    Get started with Browserbase and Playwright in Python.
  </Card>
</CardGroup>

<Steps>
  <Step title="Get your API key">
    Your API key and Project ID are displayed in the [Dashboard Navigation row](https://www.browserbase.com/sessions):

    <Frame>
      <img src="https://mintcdn.com/browserbase/giE_cpy18f2mWHqr/images/quickstart/api_key.png?fit=max&auto=format&n=giE_cpy18f2mWHqr&q=85&s=4ac94a8f69cec20bd17b2a8788169062" width="3410" height="1864" data-path="images/quickstart/api_key.png" />
    </Frame>

    Copy your API key and update your `.env` by adding the `BROWSERBASE_API_KEY` entry.

    Alternatively, you can temporarily set the environment variable for a single bash command by prefixing it with `BROWSERBASE_API_KEY=<your_api_key>` in your terminal.
  </Step>

  <Step title="Install Playwright">
    <Tabs>
      <Tab title="Node.js">
        ```bash theme={null}
        npm i playwright-core @browserbasehq/sdk
        ```

        <Note type="warning">
          Bun doesn't currently support Playwright.
        </Note>
      </Tab>

      <Tab title="Python">
        ```bash theme={null}
        pip install playwright browserbase
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Update your code or clone a template">
    Running your existing code with Browserbase only requires a few line changes:

    <Tabs>
      <Tab title="Node.js">
        ```typescript theme={null}
        import { chromium } from "playwright-core";
        import Browserbase from "@browserbasehq/sdk";

        const bb = new Browserbase({
          apiKey: process.env.BROWSERBASE_API_KEY,
        });

        (async () => {
          const session = await bb.sessions.create();
          console.log(`Session created, id: ${session.id}`);

          const browser = await chromium.connectOverCDP(session.connectUrl);
          const defaultContext = browser.contexts()[0];
          const page = defaultContext.pages()[0];

          await page.goto("https://www.browserbase.com/", {
            waitUntil: "domcontentloaded",
          });

          const debugUrls = await bb.sessions.debug(session.id);
          console.log(
            `Session started, live debug accessible here: ${debugUrls.debuggerUrl}.`,
          );

          console.log("Taking a screenshot!");
          await page.screenshot({ fullPage: true });

          console.log("Shutting down...");
          await page.close();
          await browser.close();

          console.log(
            `Session complete! View recording at https://browserbase.com/sessions/${session.id}`,
          );
        })();
        ```

        <Note>Set your `BROWSERBASE_API_KEY` in the environment variables.</Note>
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        from playwright.sync_api import Playwright, sync_playwright
        from browserbase import Browserbase
        import os

        bb = Browserbase(api_key=os.environ["BROWSERBASE_API_KEY"])


        def run(playwright: Playwright) -> None:
            session = bb.sessions.create()
            print("Session recording URL:", f"https://browserbase.com/sessions/{session.id}")

            chromium = playwright.chromium
            browser = chromium.connect_over_cdp(session.connect_url)
            context = browser.contexts[0]
            page = context.pages[0]

            page.goto("https://browserbase.com/")
            page_title = page.title()
            print(page_title)

            page.close()
            browser.close()
            print("Done!")


        if __name__ == "__main__":
            with sync_playwright() as playwright:
                run(playwright)
        ```

        <Note>Set your `BROWSERBASE_API_KEY` in the environment variables.</Note>
      </Tab>
    </Tabs>

    <br />
  </Step>

  <Step title="Inspect the completed session">
    Find your recent sessions on the overview dashboard:

    <Frame>
      <img src="https://mintcdn.com/browserbase/giE_cpy18f2mWHqr/images/quickstart/dashboard.png?fit=max&auto=format&n=giE_cpy18f2mWHqr&q=85&s=79f6a7a4e22d8f8fba56321a5f4435bb" width="3426" height="1870" data-path="images/quickstart/dashboard.png" />
    </Frame>

    Select a session to inspect it with the [Session Inspector](/platform/browser/observability/observability).
  </Step>
</Steps>

## Start building

<CardGroup cols={2}>
  <Card title="Using browser sessions" icon="browser" iconType="sharp-solid" href="/platform/browser/getting-started/using-browser-session">
    Learn how to connect to and interact with browser sessions effectively.
  </Card>

  <Card title="Managing sessions" icon="circle-stop" iconType="sharp-solid" href="/platform/browser/getting-started/manage-browser-session">
    Understand how to properly end sessions and manage their lifecycle.
  </Card>
</CardGroup>
