Skip to main content

Get started with a Playwright Node.js template

Get started with Browserbase and Playwright in Node.js.

Get started with a Playwright Python template

Get started with Browserbase and Playwright in Python.
1

Get your API key

Your API key is displayed in the Dashboard Navigation row. The API key is all you need to get started. The project is inferred from your API key.
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.
2

Install Playwright

3

Update your code or clone a template

Running your existing code with Browserbase only requires a few line changes:
Node.js
Set your BROWSERBASE_API_KEY in the environment variables.

4

Inspect the completed session

Find your recent sessions on the overview dashboard:
Select a session to inspect it with the Session Inspector.

Expected output

The Node.js example logs a session ID, a live debug URL, and a completion message:
The session ID and URLs differ on each run. Open the recording URL to inspect the completed session. The Python example prints the session replay URL, the page title, and Done!.

Cleanup

The Node.js example closes the browser in finally, including when navigation or the screenshot fails. Its session has a 60-second timeout to bound resource use if the connection fails before cleanup can run. The example keeps the screenshot in memory and writes no image file. The Python example closes the page and browser after a successful run. If it fails earlier, release the session from the dashboard or wait for the project session timeout.

Start building

Using browser sessions

Learn how to connect to and interact with browser sessions effectively.

Managing sessions

Understand how to properly end sessions and manage their lifecycle.