/browser-harness:browser-harnessfrom browser-harness
Always use browser-harness for any web interaction: automation, scraping, testing, or site/app work.
Ships in browser-harness. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Direct browser control via CDP. For task-specific edits, use browser-workspace/browser_helpers.py. For setup, install, or connection problems, read https://github.com/raystyle/browser-harness/blob/main/install.md.
A basic fetch of public information needs no browser. If a plain HTTP request can read it — a public page, an API, docs — use curl or your fetch tool, and leave the browser alone. Use browser-harness when the task needs interaction (click, type, navigate), the user's logged-in session, JS rendering, or a bot-protected page. If a direct fetch fails or returns a shell page, then escalate to the browser.
Domain skills are off by default. Set BH_DOMAIN_SKILLS=1 to enable them; see the bottom section.
If BH_DOMAIN_SKILLS=1 and the task is site-specific, read every file in the matching $BH_BROWSER_WORKSPACE/domain-skills/<site>/ directory before inventing an approach.
@'
print(page_info())
'@ | browser-harness
browser-harness. On Windows PowerShell use a here-string piped to
the command (@'... '@ | browser-harness); on macOS/Linux a heredoc works.run.py calls ensure_daemon() before exec.new_tab(url), not goto_url(url). The daemon
preserves the attached tab across separate CLI invocations, so do not call
new_tab() again in every script.current_tab() and list_tabs() and use switch_tab() to reuse a matching
tab. Do not leave duplicate tabs on the same URL or close tabs you did not
create.new_tab() and switch_tab() attach and move the horse marker without
changing Chrome's visible tab. Screenshots and normal CDP input work in the
background; call activate_tab(target) only when the user explicitly asks
or a page demonstrably pauses rendering while hidden.scroll(x, y, dx, dy) on an attached background tab is evidence
that the page needs to be visible. Call activate_tab(current_tab()), retry
the same scroll once, then re-read the scroll position. This visibly switches
tabs, so do not use it when the user has forbidden foreground changes. Do not
invent a Runtime.evaluate scroll replacement or a cross-frame JS walker.BU_NAME=x-monitor), so capture rounds never race ad-hoc CLI scripts for
the default daemon's tab attachment. Both daemons may attach to the same
agent Chrome concurrently.BU_CDP_URL=http://127.0.0.1:9223 in <BH_HOME>/.env — it never attaches
to the user's own Chrome, even one with the chrome://inspect remote-debugging
toggle enabled (that toggle's DevToolsActivePort would otherwise be
discovered first). If the agent Chrome is down, ensure_daemon launches it.
The port comes from BH_AGENT_CDP_PORT (default 9223); a WSL2 host on
mirrored networking shares loopback with Windows, so its stack pins its own
port (e.g. 9224) to not collide with the Windows stack's agent Chrome.
BH_CHROME_HEADLESS=1 launches the agent Chrome headless (default on
display-less Linux).BU_CDP_URL/BU_CDP_WS (per
call or in <BH_HOME>/.env); see the X section below.run_app(name, *args, json_output=False) — it runs exactly
browser-harness <name> <args> and returns its stdout. web_fetch(url) is
the direct pre-imported alias for browser-harness web-fetch <url> (plain
HTTP first, browser upgrade on bot walls; current page:
extract_page_content()). Long-running supervisors (x-monitor) stay in rmux.--once (one-shot task) or
--batch (batch task — the invocation IS the batch) and the task stops
what it cold-started (default daemon + agent Chrome) at exit; a stack that
was already running (persistent task, monitoring) is never touched.
Default is persistent: the daemon shuts down after BH_IDLE_TIMEOUT
(default 30 min, 0 disables) with no request, and the last daemon standing
then closes the agent Chrome (x-monitor's capture rounds refresh activity,
so a monitoring stack never idles out).--once/--batch tasks run on their OWN browser
stack — dedicated daemon name (task-<hex>), debug port (9230+,
kernel-reserved against double-pick), and a best-effort clone of the base
login profile (caches skipped, locked files degrade to placeholders). The
stack pins itself via BU_CDP_URL=127.0.0.1:<port>, so it can never reach
the user's Chrome or the shared stack. Everything is torn down at exit:
browser closed the CDP way (Browser.close — clean state, no restore
bubble), daemon stopped, task profile deleted. Add --shared to run on
the shared persistent stack instead; a pinned BU_NAME/BU_CDP_URL
(e.g. .env, monitoring) also opts out. Tasks therefore never jockey tabs
on one browser — ensure_app_tab/tab bookkeeping is for the shared
persistent stack only; inside an isolated task just new_tab() freely.browser-workspace/ is an agent-owned runtime directory, not package source.
Only add task-specific helpers and data here; do not edit the installed package.
BH_HOME, default ~/.config/browser-harness;
Windows: C:\Users\<user>\.config\browser-harness) — in every install mode,
including a git checkout. The repo's browser-workspace/ holds tracked
reference content only.BH_BROWSER_WORKSPACE (legacy BH_AGENT_WORKSPACE
still honored; a pre-v0.6.8 default agent-workspace/ is auto-renamed on
first run).browser_helpers.py, standalone scripts in apps/<name>.py — invoked as
browser-harness <name> [args...] (positional args land in APP_ARGS).
Long-running plugins get a rmux session (browser-harness rmux ensure ...).browser_helpers.py loading is a merge: packaged helpers fill the defaults,
the workspace copy overrides per function — create it only to customize; an
absent file always uses the newest packaged helpers.browser_helpers.py in the active workspace. Its public
functions are imported automatically by the next browser-harness script:def summarize_current_page():
info = page_info() or {}
body = js("(document.body && document.body.innerText || '').slice(0, 3000)")
return {"url": info.get("url"), "title": info.get("title"), "body": body}
Then invoke without importing:
@'
print(summarize_current_page())
'@ | browser-harness
x_tweets.db, heartbeats, supervisor logs.browser-workspace/domain-skills/<host>/. When
BH_DOMAIN_SKILLS=1, read every matching file before inventing an approach.The package is a thin core (daemon, helpers, rmux, diagnostics); applications are workspace plugins in browser-workspace/apps/, provisioned by browser-harness --update (or skills sync). Route by intent:
| User intent | App / command |
|---|---|
| X 持续抓推 / 监控新推(自愈) | browser-harness x-monitor(插件) |
| X 已存推的查询 / 搜索 / 统计 | browser-harness x-search ...(插件) |
| Google 搜索 | browser-harness google-search <query>(插件) |
| Bing 搜索 | browser-harness bing-search <query>(插件) |
| 网页正文提取 | browser-harness web-fetch <url>(插件) |
| 登录态跨设备迁移 | browser-harness cookies export|import(插件,S007) |
| 无头/有头切换(登录录入走有头) | browser-harness chrome-mode status|headed|headless(核心,S008) |
| rmux 会话管理 | browser-harness rmux list|status|ensure|capture|kill|kill-server(核心) |
Plugin development & testing spec: docs/references/R003-插件开发与测试规范.md.
If the daemon cannot connect, run diagnostics:
browser-harness --doctor
If Chrome is not running at all, the harness launches it automatically and retries.
If Chrome is running but remote debugging is not enabled, the harness opens:
chrome://inspect/#remote-debugging
On macOS, when Chrome asks for remote-debugging permission, run:
browser-harness mac-approve
Continue browser work when it returns ready; otherwise follow its printed
instruction.
Chrome 144+ shows a per-connection "Allow remote debugging?" prompt. Keep these steps non-blocking and wizard-style: announce → user authorizes → confirm → continue. When command output contains a blocking signal, stop and tell the user exactly what to click — never retry in a loop or leave them staring at a dialog:
| Signal in output | Tell the user to... |
|---|---|
Chrome is asking "Allow remote debugging?" | click the Chrome popup's Allow button |
permission-blocked: ... not been accepted | the previous attempt timed out; the popup is asking again — click Allow now, then retry once |
handshake-wait: ... popup, click Allow | click Allow in the Chrome popup |
remote debugging is turned off ... chrome://inspect/#remote-debugging | open chrome://inspect/#remote-debugging and tick "Allow remote debugging" |
macOS mac-approve / popup | run browser-harness mac-approve or click Allow |
Approval is per-connection: each new daemon handshake can show the popup again.
After the user clicks Allow, verify with browser-harness --doctor that
active browser connections is 1 before continuing.
cdp("Accessibility.getFullAXTree")["nodes"] has every element's role, name, and backendDOMNodeId — filter in Python before printing (it is thousands of nodes). Node role is a property object, not a plain string, and its nesting varies by Chrome version — normalize it:
v = n.get("role") or {}; role = v if isinstance(v, str) else (v.get("value") if isinstance(v.get("value"), str) else (v.get("value") or {}).get("value", "")).
Coordinates: q = cdp("DOM.getBoxModel", backendNodeId=n)["model"]["content"]; x, y = sum(q[0::2])/4, sum(q[1::2])/4 (viewport px, ready for click_at_xy; negative/oversized means scroll first).click_at_xy(x, y) -> verify with a targeted js(...)/page_info() check. A click that dispatches without effect on a hidden tab needs the same activate_tab treatment as a timed-out scroll.js(...) only when the AX tree lacks the element (canvas, exotic widgets); screenshot when layout or imagery matters — capture_screenshot() returns a PNG file path, not base64.wait_for_element(sel)
when the target is known (the most task-true judge); wait_for_render()
for general settle (DOM quiet + compositor heartbeat — tells a settled page
from a frozen renderer); wait_for_load() suits static pages. Reserve
wait_for_network_idle() for waits whose target genuinely is one specific
data request — long-polling/SSE/analytics beacons never go idle, and idle
≠ rendered (an SPA renders after its data arrives).ensure_real_tab().js(...) for DOM inspection or extraction when coordinates are the wrong tool.cdp("Domain.method", ...).Two pieces: the x-supervisor workspace app (self-healing loop) plus the
x-worker app it spawns into a rmux pane. Agent-operated, no autostart;
browser-harness --update (or skills sync) installs them.
Ad-hoc X search (x.com/search?q=...&f=live): the timeline renders only
after a scroll — virtual scrolling holds even the first article back
until a window.scrollBy event arrives. Navigate, wait ~6s, then loop
scroll → wait → harvest article nodes, dedup by text prefix; stop on 3
consecutive scrolls with nothing new (that is the true bottom — the feed
ends, it is not infinite). One query supplies a FIXED window of ~10-20
tweets however hot the term: for full coverage, time-slice the query
(since:YYYY-MM-DD / until:YYYY-MM-DD operators) and harvest each window
— 2 windows measurably beat the single-window cap. Stored-tweet lookup
needs no browser: browser-harness x-search <keyword>.
Run as rmux background sessions (reuse one shell; poll on demand — no blocking
command). The worker runs against an isolated agent Chrome — never the
user's own Chrome — via BU_CDP_URL.
browser-harness x-monitor
-> isolated Chrome on <BH_HOME>/agent-chrome-profile + port
BH_AGENT_CDP_PORT (default 9223); rmux
sessions x-supervisor (supervisor) and x-monitor (worker).
Windows first; WSL2 works headless (S006) once the agent profile is
logged in to X on that host.browser-harness rmux status # are both sessions alive?
heartbeat freshness at browser-workspace/x_worker.heartbeat
browser-harness rmux capture x-monitor # worker stdout
browser-harness x-search --stats # how many tweets are storedbrowser-harness rmux kill x-monitor (the supervisor respawns
on anomaly); stop the supervisor with browser-harness rmux kill x-supervisor.Worker env vars:
X_INTERVAL (default 600) seconds between refresh rounds.X_IDLE_THRESHOLD (default 10) seconds of no keyboard/mouse required before a
foreground refresh is allowed.X_IDLE_WAIT (default 60) max seconds to wait for idle while you are active;
if you stay active, that round is skipped (no focus steal).X_FOREGROUND=0 disables foreground refresh entirely (pure background).X_DOCK_W / X_DOCK_H (default 520x200) the small taskbar-docked window size.When the X page is hidden (minimized / background tab) and the user is idle, the worker shrinks the window to that docked pane, activates the tab to defeat Chrome's intensive throttling, captures, then minimizes it again.
Tweets are stored in <BH_HOME>/browser-workspace/x_tweets.db (deduped, WAL,
searchable). Tweet author holds the display name only; handle is separate.
When the user asks to analyze:
browser-harness x-search --recent --limit N or --since 1h
or read the live timeline through the browser when "right now" matters.browser-harness x-search <keyword> (--author X matches display name or
@handle, --limit N, --group-by day|hour, --csv [--csv-out path.csv]).
A primary mode is required: <keyword>, --recent, --since, or --stats.browser-harness x-search --stats
(totals, distinct authors, posted/seen range, top authors)Workspace helpers google_search(query, limit) and bing_search(query, limit) each
reuse their own tab, extract [{title, url}, ...], and return them. Use them when
the user asks to search Google or Bing (runs in the real, logged-in browser):
google_search("rust web framework", limit=5)
bing_search("rust web framework", limit=5)
To read the clean text of a web page (article / docs / any URL), use defuddle. It strips nav, ads, and boilerplate and returns the main content as Markdown + metadata. Prefer a plain fetch for public pages; use the browser only for logged-in or JS-only pages.
In a browser script:
extract_url_content("https://example.com/article", markdown=True) # plain HTTP
extract_url_content("https://x.com/home", markdown=True, use_browser=True) # reuse session
extract_page_content(markdown=True) # current tab
Returns {title, url, domain, author, published, description, image, favicon, language, site, word_count, markdown, text, content_html, engine}.
Or from the shell (no browser needed for public pages):
browser-harness web-fetch "https://example.com/article" # markdown
browser-harness web-fetch "https://example.com/article" --text # plain text
browser-harness web-fetch "https://example.com/article" --json # full metadata
browser-harness web-fetch "https://x.com/home" --browser # reuse session
browser-harness web-fetch --current # current tab
Engine order: pydefuddle (Python, bundled as a core dependency), then a
stdlib/bs4 fallback. The engine field says which one was used. No Node/npx
dependency.
To know whether there is an operable browser (Chrome running + remote debugging enabled + daemon connected), poll:
browser-harness doctor --json # parse daemon.browser_ready / chrome_running
or run the setup wizard — a guided, step-by-step flow that auto-opens Chrome,
reminds for remote-debugging / Allow, and creates one tab per app (X, Google,
Bing). These scripts live in a git checkout's browser-workspace/ and are not
part of the installed package:
uv run python browser-workspace/browser_wizard.py # repo checkout only
or watch it continuously — this also auto-opens Chrome when none is running, then reports when the daemon becomes connected:
uv run python browser-workspace/browser_watch.py # repo checkout only
In a browser script, setup_browser_apps() ensures X / Google / Bing each have
their own tab and returns the target ids.
Use the resource views to check the attached browser before operating:
browser-harness browsers # Chrome instances, tabs, app-tab binding, rmux state
browser-harness current # currently attached target + CDP attach state
browsers marks each instance as agent or user by profile path.agent-chrome-profile on BH_AGENT_CDP_PORT
(default 9223); it never touches the user's normal profile.setup_browser_apps() is idempotent and mutex-like: X, Google, and Bing each
reuse their own tab rather than opening duplicates.Fresh installs do not record. Users can enable local background traces:
browser-harness recordings enable
browser-harness recordings disable
browser-harness recordings
BH_RECORD=1 or BH_RECORD=0 overrides the preference for one process. Any
natural nudge to “record,” “show,” “demo,” or “make a video” opts in that task;
significant work alone does not.
Before browser work, call start_recording(name, title=...), retain its exact
returned directory, and call stop_recording() after verifying the result.
Never replace that path with recordings --latest. For a request made after
the task, use:
browser-harness recordings --latest
Use it only if timestamps and pages match; otherwise say the work was not captured. Never reenact a completed task. For a video, follow make-video.md. If sub-agents are available, they may handle post-production from the exact recording path while the main agent returns the task result.
If you get stuck on a browser mechanic, check the interaction skills — when this
skill is installed they sit right next to this file under references/interaction/;
upstream they live at https://github.com/raystyle/browser-harness/tree/main/interaction-skills.
BU_CDP_URL, or
BU_CDP_WS.BH_REQUIRE_EXISTING_DAEMON=1. Each CLI call then health-checks and reuses
that daemon or fails closed; it never auto-starts or discovers another Chrome.$BH_BROWSER_WORKSPACE/browser_helpers.py.chrome://inspect/#remote-debugging must be enabled for local Chrome control.browser-harness mac-approve. Do not poll in a loop — the daemon holds one connection.BU_CDP_URL is an HTTP DevTools endpoint; the daemon resolves it to WebSocket.browser-harness CLI, never a bare python -m browser_harness.daemon
(interpreter-base mixing, M109).[inspect-toggle] section of browser-harness browsers. Keep the
default daemon pinned via BU_CDP_URL so it can never ride the user's
browser.BH_IPC_TIMEOUT), goto_url's Page.navigate 30s
(BH_NAVIGATE_TIMEOUT), screenshots 60s (BH_SCREENSHOT_TIMEOUT). When the
navigate response is lost to the deadline, goto_url adjudicates from the
buffered event stream (Page.frameNavigated commit / chrome-error failure
/ silent deadline = unknown) and only raises on the silent case. Raw
cdp("Page.navigate", ...) gets none of this — prefer goto_url (Issue #3).Only applies when BH_DOMAIN_SKILLS=1. Otherwise ignore domain skills.
When enabled, look up $BH_BROWSER_WORKSPACE/domain-skills/<dir>/ before
inventing an approach. Directory name = the hostname's first label after
stripping a leading www.: github.com → github/, www.bing.com →
bing/. Subdomains are their own site — maps.google.com → maps/ (not
google/); that is why gmail is a directory of its own.
goto_url(...) returns up to 10 .md filenames for the navigated host (set
BH_DOMAIN_SKILLS=1 in the same process for the hint). Bundled helper
scripts (e.g. claude-ai/extract-share-transcript.py) are not listed — list
the directory itself to find them. browser-harness skills sync (also run by --update) provisions
the packaged site skills into the workspace (additively — locally added site
skills are never deleted; only this project's own retired pre-v0.4.0 filenames
are pruned on sync).
references/install.md (opens in a new tab)references/interaction/connection.md (opens in a new tab)references/interaction/cookies.md (opens in a new tab)references/interaction/cross-origin-iframes.md (opens in a new tab)references/interaction/dialogs.md (opens in a new tab)references/interaction/downloads.md (opens in a new tab)references/interaction/drag-and-drop.md (opens in a new tab)references/interaction/dropdowns.md (opens in a new tab)references/interaction/iframes.md (opens in a new tab)references/interaction/make-video.md (opens in a new tab)references/interaction/network-requests.md (opens in a new tab)references/interaction/print-as-pdf.md (opens in a new tab)references/interaction/screenshots.md (opens in a new tab)references/interaction/scrolling.md (opens in a new tab)references/interaction/shadow-dom.md (opens in a new tab)references/interaction/tabs.md (opens in a new tab)references/interaction/uploads.md (opens in a new tab)references/interaction/viewport.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub raystyle/browser-harness-py --plugin browser-harnessOther plugins' skills for the same job