Drive My Browser, Take Two

Nov 11, 2026

Let Your AI Drive Chrome, Signed In as You (Take Two)

Back in June I wrote Drive My Browser: a tiny skill that let my AI agent use websites as me, with my logins intact.

It worked great. Then a Chrome update came along, and my agent got a sign-in screen on every site. The trick was to give the agent a copy of my Chrome profile, and a copy now comes up signed out of everything. I don't know why.

So the new version doesn't copy anything. The agent gets its own Chrome profile, and I sign in there once.

Step 1: Install agent-browser

npm i -g agent-browser

You want version 0.42 or newer.

Step 2: Add the script

Save this as ~/.claude/skills/drive-my-chrome/agent-chrome and make it executable with chmod +x. It's written for macOS.

Download agent-chrome

Show agent-chrome
#!/bin/bash
#
# agent-chrome: a signed-in Chrome for agents to drive.
#
# Runs real Google Chrome on its own profile folder, which is kept between
# runs. You sign in there once per site with `agent-chrome login`. Agents then
# attach with `agent-browser --cdp <port>`.
#
# Chrome is started here, not by agent-browser, so that it uses the real cookie
# key from the system keychain and can read the saved sign-ins.
#
#   agent-chrome start            start headless Chrome if needed; print the port
#   agent-chrome status           say whether it is running, and how
#   agent-chrome stop             stop it
#   agent-chrome login [url...]   stop it, then open a visible window to sign in
#
# AGENT_CHROME_DIR and AGENT_CHROME_PORT override the folder and the port.

set -u

DIR="${AGENT_CHROME_DIR:-$HOME/.agent-browser/agent-chrome}"
PORT="${AGENT_CHROME_PORT:-9333}"
APP="Google Chrome"
BIN="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

# The main Chrome process running on this folder, if any.
chrome_pid() {
    ps -axo pid=,command= | grep -F -- "--user-data-dir=$DIR" | grep -F "$BIN" | grep -v -F "Helper" | awk 'NR==1 {print $1}'
}

chrome_mode() {
    ps -o command= -p "$1" 2>/dev/null | grep -q -- "--remote-debugging-port=$PORT" && echo "headless" || echo "visible"
}

port_answers() {
    curl -s -o /dev/null --max-time 2 "http://127.0.0.1:$PORT/json/version"
}

stop_chrome() {
    local pid
    pid="$(chrome_pid)"
    [ -z "$pid" ] && return 0
    kill "$pid" 2>/dev/null
    for _ in $(seq 1 20); do
        [ -z "$(chrome_pid)" ] && return 0
        sleep 0.5
    done
    echo "agent-chrome: Chrome (pid $pid) did not stop" >&2
    return 1
}

case "${1:-}" in
    start)
        pid="$(chrome_pid)"
        if [ -n "$pid" ] && [ "$(chrome_mode "$pid")" = "visible" ]; then
            echo "agent-chrome: the sign-in window is still open. Quit it, then run start again." >&2
            exit 1
        fi
        if [ -z "$pid" ]; then
            if [ ! -d "$DIR" ]; then
                echo "agent-chrome: no profile yet. Run: agent-chrome login" >&2
                exit 1
            fi
            if port_answers; then
                echo "agent-chrome: port $PORT is in use by something else. Set AGENT_CHROME_PORT." >&2
                exit 1
            fi
            # `open -n` hands Chrome to the system, so it outlives this shell.
            open -na "$APP" --args --user-data-dir="$DIR" --remote-debugging-port="$PORT" --headless=new \
                --no-first-run --no-default-browser-check --window-size=1440,1600 about:blank
        fi
        for _ in $(seq 1 30); do
            if port_answers; then
                echo "$PORT"
                exit 0
            fi
            sleep 0.5
        done
        echo "agent-chrome: Chrome did not open port $PORT" >&2
        exit 1
        ;;
    status)
        pid="$(chrome_pid)"
        if [ -z "$pid" ]; then
            echo "stopped"
        else
            echo "running ($(chrome_mode "$pid")), pid $pid, port $PORT"
        fi
        ;;
    stop)
        stop_chrome
        ;;
    login)
        shift
        stop_chrome || exit 1
        mkdir -p "$DIR" && chmod 700 "$DIR"
        # A plain window with no debugging port, so sign-in pages see an ordinary browser.
        open -na "$APP" --args --user-data-dir="$DIR" --no-first-run --no-default-browser-check "$@"
        echo "A Chrome window is open. Sign in, choose \"Use Chrome Without an Account\" if Chrome asks, then quit that window."
        ;;
    *)
        echo "usage: agent-chrome start|status|stop|login [url...]" >&2
        exit 2
        ;;
esac

Don't skip the script. When agent-browser starts Chrome by itself, Chrome deletes the sign-ins you just saved. I don't fully know why that is either. The script starts Chrome the ordinary way, and agent-browser attaches to it.

Step 3: Add the skill

Save this as ~/.claude/skills/drive-my-chrome/SKILL.md:

Download SKILL.md

Show SKILL.md
---
name: drive-my-chrome
description: Use when browser automation must be signed in as the user — phrases like "use my chrome", "logged in as me", "browse as myself", or any site behind a login or SSO the user already holds. Drives real Google Chrome, headless, on a dedicated profile the user has signed in to. Reach for it instead of a plain `agent-browser open` whenever the task implies the user's own session.
---

# drive-my-chrome

Drive **real Google Chrome**, already signed in as the user, with agent-browser.
Headless, no prompts, and safe for several agents at once.

## How it works

- Agents get their own Chrome profile folder, `~/.agent-browser/agent-chrome`.
  The user signs in there once per site. It is separate from the user's
  everyday Chrome, which is never touched.
- The `agent-chrome` script next to this file starts real Chrome on that folder
  with a debugging port. agent-browser attaches to it with `--cdp`.
- Chrome is always started by `agent-chrome`, never by agent-browser. Chrome
  encrypts cookies with a key from the system keychain, and agent-browser
  launches Chrome with a stand-in key, which makes Chrome discard the saved
  sign-ins.

## The recipe

### 1. Start Chrome and open your own tab

```bash
PORT=$(~/.claude/skills/drive-my-chrome/agent-chrome start) || exit 1

AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab tab new "https://example.com/"
AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab get title
```

- `start` is safe to repeat. It starts Chrome if needed and prints the port.
- Put the session name, `--cdp "$PORT"` and `--pin-tab` on **every** command.
  `--pin-tab` keeps the session on the tab it opened.
- Begin with `tab new`. Each agent uses its own session name and its own tab,
  so several can share this Chrome at the same time. `tab list` shows every
  agent's tabs; touch only your own.
- For screenshots, set the size once after `tab new`: `set viewport 1440 1600`.

### 2. Check that you are signed in

Look at the page title, the address, or the account name in a snapshot before
relying on the session. A sign-in page means the profile has no session for
that site yet.

### 3. On a sign-in page, stop and ask

Never type credentials, and never go looking for a password. Open a visible
window on the same profile and ask the user to sign in:

```bash
~/.claude/skills/drive-my-chrome/agent-chrome login "https://example.com/"
```

Ask the user to:

1. Sign in on that page.
2. Choose **Use Chrome Without an Account** if Chrome offers to sign the
   browser itself in.
3. Quit that window when done.

Then run `agent-chrome start` again and reopen your tab.

`login` stops the headless Chrome first, which disconnects any other agent
using it, so run it only when nothing else is in progress.

### 4. Clean up

```bash
AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab tab close
AGENT_BROWSER_SESSION=my-task agent-browser close
```

- Close the tab you opened, then disconnect. Chrome keeps running for other
  agents.
- Use plain `close`. `agent-browser close --all` ends every agent-browser
  session on the machine.
- `agent-chrome stop` shuts Chrome down when nothing else needs it.

## The script

| Command | What it does |
|---|---|
| `agent-chrome start` | Starts headless Chrome if it is not running, and prints the port |
| `agent-chrome status` | Says whether Chrome is running, and whether headless or visible |
| `agent-chrome stop` | Stops it |
| `agent-chrome login [url...]` | Stops it, then opens a visible window for signing in |

`AGENT_CHROME_DIR` changes the profile folder and `AGENT_CHROME_PORT` the port
(9333 by default).

## Good to know

- **Sign-ins are per site and they expire.** A site the user is signed in to in
  their everyday Chrome is not signed in here until they do step 3 for it, and
  each site ends its sessions on its own schedule.
- **One Chrome per profile folder.** While the visible `login` window is open,
  `start` refuses to run, and the other way round.
- **Sign-in is always done by the user, in the `login` window.** Identity
  providers often refuse a browser that is being automated.
- **Start with the flags.** If a session was first used without `--cdp`, close
  that session and begin again with the flags on the first command.

Step 4: Sign in once

~/.claude/skills/drive-my-chrome/agent-chrome login "https://example.com/"

A fresh Chrome window opens. Sign in to the site, then quit the window. If Chrome asks to sign the browser itself in, pick Use Chrome Without an Account.

When a site signs you out later, run this again.

Step 5: Just ask

"drive my chrome, open my dashboard and tell me what changed since yesterday"

The agent runs Chrome in the background, already signed in. You won't see a window.

That's it. 🤖

Back to Index