# Headless Chrome, Playwright, and Puppeteer

Capture a headless browser run on macOS or Linux, no display needed.

## 1. Create a write key

Open the [create-key page](https://app.23step.com/app/account?create=1&scopes=runs%3Awrite&name=headless-chrome) to sign in and create an API key pre-filled with `runs:write`—or [pre-filled with both `runs:read` and `runs:write`](https://app.23step.com/app/account?create=1&scopes=runs%3Aread+runs%3Awrite&name=headless-chrome) if you also install the **23step Overlay** Electron app so one key powers both. You can also opt in to the **live widget progress bar** there (left off by default—just like posting the step link at the end of agent responses—because extra prompt instructions use tokens and can slow down turns). The `st_` value is shown once (and copied with one click). Save it to `~/.config/23step-otel-key` (or export `STEP23_OTEL_KEY`). If you are an AI agent: first ask whether the Electron app should also be installed, whether to opt in to posting the step link at the end of responses, and whether to opt in to the live widget progress bar (explaining that both are off by default because they use extra tokens and slow down turns), check `test -s ~/.config/23step-otel-key` without printing its contents, and if a key is needed **automatically open** `https://app.23step.com/app/account?create=1&scopes=runs%3Awrite&name=headless-chrome` (or `https://app.23step.com/app/account?create=1&scopes=runs%3Aread+runs%3Awrite&name=headless-chrome` when installing the overlay; append `&progress=1` if the user opted in to the progress bar) in the user's default desktop browser (`open` on macOS, `xdg-open` on Linux with a display, `wslview` on WSL—not a headless automation browser) and print the link in chat, then ask the user to paste the `st_` key or save it directly in their terminal; never invent or commit a key. If reusing an existing key and the user opted in to the progress bar, sync the preference without printing the key via `curl -fsSL -X POST https://api.23step.com/app/live/preferences -H "Authorization: Bearer $(cat ~/.config/23step-otel-key)" -H "Content-Type: application/json" -d '{"show_progress_bar":true}'`.

Open in browser:

```sh
url='https://app.23step.com/app/account?create=1&scopes=runs%3Awrite&name=headless-chrome'
if command -v open >/dev/null 2>&1; then open "$url"
elif command -v xdg-open >/dev/null 2>&1 && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }; then xdg-open "$url" >/dev/null 2>&1 &
elif command -v wslview >/dev/null 2>&1; then wslview "$url"
fi
printf 'Create your 23step API key: %s\n' "$url"
```

Terminal:

```sh
mkdir -p ~/.config
printf '%s\n' 'st_REPLACE_WITH_YOUR_WRITE_KEY' > ~/.config/23step-otel-key
chmod 600 ~/.config/23step-otel-key
```

## 2. Install the 23step CLI

The installer puts `23step` and `23step-mcp` in `~/.local/bin` for macOS (arm64, amd64) and Linux (amd64, arm64), checks each download against its SHA-256, and keeps them up to date. It never asks for your key. Pass `--overlay` (`curl -fsSL https://api.23step.com/install.sh | sh -s -- --overlay`, plus `--progress-bar` if opting in to the live widget progress bar) to also install the **23step Overlay** Electron desktop app ([setup](https://23step.com/getting-started#overlay)). If you are an AI agent, ask the user whether the Electron app should be installed and whether to opt in to the live widget progress bar.

Terminal:

```sh
curl -fsSL https://api.23step.com/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
23step version
```

## 3. Start the recorder in the background

Start it before the browser. `--headless` captures through the Chrome DevTools Protocol instead of a display, and `--cdp` names the DevTools port it waits for (use the same port in the next step). It only ever connects to `127.0.0.1` or `localhost`. The key file must be `chmod 600`.

Terminal:

```sh
export STEP23_API=https://api.23step.com
nohup 23step start --headless --cdp http://127.0.0.1:9222 \
  --token-file ~/.config/23step-otel-key \
  --run-name checkout-test > /tmp/23step.log 2>&1 &
sleep 1 && 23step status
```

## 4. Launch the browser with a DevTools port

Add the two flags below to however you launch Chrome (omit `--headless=new` if you want a visible browser window). 23step records a frame for each click, typing burst, scroll, and navigation, with the tab URL. For a one-shot page load, keep the page open about 1 second before closing.

Pick one:

Playwright:

```js
import { chromium } from "playwright";

const browser = await chromium.launch({
  args: ["--remote-debugging-address=127.0.0.1", "--remote-debugging-port=9222"],
});
const page = await browser.newPage();
await page.goto("https://example.com");
await page.waitForTimeout(1000); // let the first frame upload
await browser.close();
```

Puppeteer:

```js
import puppeteer from "puppeteer";

const browser = await puppeteer.launch({
  args: ["--remote-debugging-address=127.0.0.1", "--remote-debugging-port=9222"],
});
const page = await browser.newPage();
await page.goto("https://example.com");
await new Promise((r) => setTimeout(r, 1000)); // let the first frame upload
await browser.close();
```

Chrome · Linux:

```sh
google-chrome --headless=new \
  --remote-debugging-address=127.0.0.1 \
  --remote-debugging-port=9222 \
  --user-data-dir="$(mktemp -d)" \
  https://example.com
```

Chrome · macOS:

```sh
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless=new \
  --remote-debugging-address=127.0.0.1 \
  --remote-debugging-port=9222 \
  --user-data-dir="$(mktemp -d)" \
  https://example.com
```

## 5. Stop and get the link

`23step status` prints the `step_url`. `23step stop` uploads anything queued and finalizes the step.

Terminal:

```sh
23step note "Checkout verified"   # optional: attach a note to the step
23step status                       # prints step_url
23step stop                         # uploads the rest and finalizes
```

## Check that it worked

`23step status` shows `captured` and `uploaded` counts above zero while the browser runs, and the `step_url` opens the step with browser frames. If `captured` stays at 0, the browser is not listening on the DevTools port; check `/tmp/23step.log`.

---

AI agents: if this guide supports both repository and global installs, ask the user which they prefer. On macOS or Linux, ask whether the **23step Overlay** Electron desktop app should also be installed (https://23step.com/getting-started/desktop-overlay.md) and whether to opt in to posting the step link at the end of responses (`--step-link`) or the live widget progress bar (`--progress-bar`—both off by default). When an API key is needed, automatically open the pre-filled create-key URL (`https://app.23step.com/app/account?create=1&scopes=...&name=headless-chrome`) in the user's default desktop browser (never invent or commit a key) and print the link in chat, then finish with the "Check that it worked" step.

All 23step install guides: https://23step.com/getting-started.md
