browserpilot-cdp 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,8 +3,13 @@
3
3
  > **Zero-click, pure-CDP Chrome Extension, MCP Server & CLI for AI Agents.**
4
4
  > Control, inspect, and debug your real logged-in Chrome browser — no Playwright/Puppeteer runtime bloat, no per-tab icon clicking, and no repetitive Chrome `--autoConnect` "Allow" confirmation popups.
5
5
 
6
+ [![npm version](https://img.shields.io/npm/v/browserpilot-cdp?color=0ea5e9)](https://www.npmjs.com/package/browserpilot-cdp)
7
+ [![CI](https://github.com/xy-tuoren/browserpilot/actions/workflows/ci.yml/badge.svg)](https://github.com/xy-tuoren/browserpilot/actions/workflows/ci.yml)
8
+ [![Node.js >= 22](https://img.shields.io/badge/node-%3E%3D22-brightgreen.svg)](https://nodejs.org/)
6
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
7
10
 
11
+ **English** | [简体中文](./README.zh-CN.md)
12
+
8
13
  ---
9
14
 
10
15
  ## Why BrowserPilot?
@@ -50,28 +55,47 @@ AI Coding Agents (Claude Code / Cursor / Codex / Antigravity / Custom SDK)
50
55
 
51
56
  ## Quick Start (1 Minute)
52
57
 
53
- ### Option 1: Install from npm (Recommended)
58
+ ### Step 1: Install CLI & Initialize
54
59
 
55
60
  ```bash
56
61
  npm install -g browserpilot-cdp
57
62
  browserpilot setup
58
63
  ```
59
64
 
60
- 1. `browserpilot setup` automatically syncs the bundled extension to a stable upgrade-proof folder (`~/.browserpilot/extension`), computes its deterministic Chrome Extension ID, and registers the **Chrome Native Messaging Host** (`com.browserpilot.bridge`) — **no copying Extension IDs or manual auth tokens required**.
61
- 2. Open `chrome://extensions` in Chrome, enable **Developer mode**, click **Load unpacked**, and select `~/.browserpilot/extension`. It connects automatically on the first millisecond!
62
- 3. Add `browserpilot` to your AI coding agent MCP config (Claude Code / Cursor / Codex / Antigravity):
63
- ```json
64
- {
65
- "mcpServers": {
66
- "browserpilot": {
67
- "command": "browserpilot",
68
- "args": ["mcp"]
69
- }
70
- }
71
- }
72
- ```
73
-
74
- ### Option 2: Build from Source
65
+ > **Prerequisites:** Node.js >= 22 (`ffmpeg` is optional, only required for video recording).
66
+ > **Non-invasive by design:** `browserpilot setup` only syncs the bundled Chrome extension to `~/.browserpilot/extension`, computes its deterministic Chrome Extension ID, and registers the **Chrome Native Messaging Host** (`com.browserpilot.bridge`). It **never** modifies your AI agents' settings or skill folders.
67
+
68
+ ### Step 2: Load the Chrome Extension (1-Time)
69
+
70
+ 1. Open `chrome://extensions` in Chrome and enable **Developer mode**.
71
+ 2. Click **Load unpacked** and select `~/.browserpilot/extension`.
72
+ 3. It connects automatically via Native Messaging on the first millisecond — **no copying Extension IDs or manual auth tokens required**, and future upgrades keep the same path & ID.
73
+
74
+ *(Skip Step 2 if you only want to drive a separate `--remote-debugging-port` Chromium instance via `browserpilot browser start` or `--cdp`.)*
75
+
76
+ ### Step 3: Connect Only the AI Agent(s) You Want (Choose Option A or B)
77
+
78
+ - **Option A — Agent Skill + CLI (Lightweight, lowest context token usage):**
79
+ Install [`skills/browserpilot/SKILL.md`](./skills/browserpilot/SKILL.md) only into the specific agent or project where you want it — for example:
80
+ ```bash
81
+ npx skills add xy-tuoren/browserpilot
82
+ ```
83
+ Or copy `skills/browserpilot/SKILL.md` (or the output of `browserpilot skill`) into a single project's `.claude/skills/browserpilot/`, `.agents/skills/browserpilot/`, etc. No MCP configuration required.
84
+
85
+ - **Option B — MCP Server (43 native `browser_*` tools + direct multimodal screenshot blocks):**
86
+ Add this snippet to the MCP config of whichever agent you want (Claude Code, Cursor, Codex, Antigravity):
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "browserpilot": {
91
+ "command": "browserpilot",
92
+ "args": ["mcp"]
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ ### Alternative: Build from Source / Direct CDP (No Extension)
75
99
 
76
100
  ```bash
77
101
  git clone https://github.com/xy-tuoren/browserpilot.git
@@ -81,7 +105,7 @@ pnpm build
81
105
  node packages/server/dist/cli.js setup
82
106
  ```
83
107
 
84
- Or connect directly to a `--remote-debugging-port` Chrome without an extension:
108
+ Or connect MCP directly to a `--remote-debugging-port` Chrome without loading the extension:
85
109
 
86
110
  ```json
87
111
  {
package/dist/cli.js CHANGED
@@ -8,11 +8,12 @@ import path7 from "node:path";
8
8
  import { fileURLToPath as fileURLToPath3 } from "node:url";
9
9
 
10
10
  // ../protocol/dist/constants.js
11
- var BROWSERPILOT_VERSION = "1.2.2";
11
+ var BROWSERPILOT_VERSION = "1.2.4";
12
12
  var DEFAULT_DAEMON_HOST = "127.0.0.1";
13
13
  var DEFAULT_DAEMON_PORT = 19888;
14
14
  var NATIVE_HOST_NAME = "com.browserpilot.bridge";
15
15
  var NATIVE_MESSAGE_MAX_BYTES = 1024 * 1024;
16
+ var NATIVE_INCOMING_MAX_BYTES = 64 * 1024 * 1024;
16
17
  var DEFAULT_CDP_TIMEOUT_MS = 15e3;
17
18
  var MAX_CONSOLE_BUFFER = 5e3;
18
19
  var MAX_NETWORK_BUFFER = 2e3;
@@ -858,7 +859,13 @@ var IGNORED_ANALYTICS_PATTERNS = [
858
859
  /posthog\.com/i,
859
860
  /datadoghq\.com/i,
860
861
  /hm\.baidu\.com/i,
861
- /\/collect\b|\/analytics\b|\/telemetry\b|\/beacon\b/i
862
+ /\/collect\b|\/analytics\b|\/telemetry\b|\/beacon\b/i,
863
+ // Long-polling & real-time push endpoints (Discourse message-bus, Socket.IO, SignalR, SSE)
864
+ /\/message-bus\//i,
865
+ /\/(long-?poll|polling|heartbeat|keepalive)\b/i,
866
+ /socket\.io/i,
867
+ /[?&]EIO=\d/i,
868
+ /\/signalr\//i
862
869
  ];
863
870
  function isIgnoredAnalyticsUrl(url) {
864
871
  return IGNORED_ANALYTICS_PATTERNS.some((re) => re.test(url));
@@ -878,7 +885,7 @@ async function waitForPageLoad(session, options = {}) {
878
885
  return;
879
886
  if (isIgnoredAnalyticsUrl(url))
880
887
  return;
881
- inflight.set(id, url);
888
+ inflight.set(id, { url, startedAt: Date.now() });
882
889
  });
883
890
  const offFin = session.on("Network.loadingFinished", (params) => {
884
891
  inflight.delete(String(params.requestId ?? ""));
@@ -886,6 +893,16 @@ async function waitForPageLoad(session, options = {}) {
886
893
  const offFail = session.on("Network.loadingFailed", (params) => {
887
894
  inflight.delete(String(params.requestId ?? ""));
888
895
  });
896
+ const countActiveInflight = (now, docComplete) => {
897
+ if (!docComplete)
898
+ return inflight.size;
899
+ let active = 0;
900
+ for (const item of inflight.values()) {
901
+ if (now - item.startedAt < 2500)
902
+ active++;
903
+ }
904
+ return active;
905
+ };
889
906
  let readyState = "loading";
890
907
  let idleSince = null;
891
908
  try {
@@ -904,17 +921,19 @@ async function waitForPageLoad(session, options = {}) {
904
921
  } catch {
905
922
  readyState = "loading";
906
923
  }
924
+ const now = Date.now();
907
925
  const stillOnBlank = Boolean(options.ignoreAboutBlank) && (!href || href === "about:blank");
908
- if (!stillOnBlank && (readyState === "complete" || readyState === "interactive") && inflight.size === 0) {
926
+ const activePending = countActiveInflight(now, readyState === "complete");
927
+ if (!stillOnBlank && (readyState === "complete" || readyState === "interactive") && activePending === 0) {
909
928
  if (idleSince === null)
910
- idleSince = Date.now();
911
- if (Date.now() - idleSince >= idleMs || readyState === "complete") {
912
- if (Date.now() - idleSince >= Math.min(idleMs, 150)) {
929
+ idleSince = now;
930
+ if (now - idleSince >= idleMs || readyState === "complete") {
931
+ if (now - idleSince >= Math.min(idleMs, 150)) {
913
932
  return {
914
933
  success: true,
915
934
  readyState,
916
935
  pendingRequests: 0,
917
- waitTimeMs: Date.now() - start,
936
+ waitTimeMs: now - start,
918
937
  timedOut: false
919
938
  };
920
939
  }
@@ -1057,14 +1076,35 @@ var LANDMARK_AND_STRUCTURE_ROLES = /* @__PURE__ */ new Set([
1057
1076
  "iframe"
1058
1077
  ]);
1059
1078
  var SKIPPED_ROLES = /* @__PURE__ */ new Set(["InlineTextBox", "LineBreak", "LayoutTable", "LayoutTableRow", "LayoutTableCell"]);
1079
+ var LEAF_LABELED_ROLES = /* @__PURE__ */ new Set([
1080
+ "link",
1081
+ "button",
1082
+ "heading",
1083
+ "tab",
1084
+ "menuitem",
1085
+ "menuitemcheckbox",
1086
+ "menuitemradio",
1087
+ "option",
1088
+ "checkbox",
1089
+ "radio",
1090
+ "switch",
1091
+ "textbox",
1092
+ "searchbox",
1093
+ "combobox"
1094
+ ]);
1060
1095
  function getProp(node, name) {
1061
1096
  const prop = node.properties?.find((p) => p.name === name);
1062
1097
  return prop?.value?.value;
1063
1098
  }
1064
- function cleanText(raw, maxLen = 140) {
1099
+ function normalizeWs(raw) {
1065
1100
  if (raw === void 0 || raw === null)
1066
1101
  return "";
1067
- const s = String(raw).replace(/\s+/g, " ").trim();
1102
+ return String(raw).replace(/\s+/g, " ").trim();
1103
+ }
1104
+ function cleanText(raw, maxLen = 140) {
1105
+ const s = normalizeWs(raw);
1106
+ if (!s)
1107
+ return "";
1068
1108
  if (s.length <= maxLen)
1069
1109
  return s;
1070
1110
  return `${s.slice(0, maxLen - 1)}\u2026`;
@@ -1090,7 +1130,7 @@ function formatAXTree(nodes, options = {}) {
1090
1130
  }
1091
1131
  }
1092
1132
  const visited = /* @__PURE__ */ new Set();
1093
- function renderNode(node, depth, parentName) {
1133
+ function renderNode(node, depth, parentName, parentLeafText) {
1094
1134
  if (depth > maxDepth || visited.has(node.nodeId))
1095
1135
  return;
1096
1136
  visited.add(node.nodeId);
@@ -1100,27 +1140,30 @@ function formatAXTree(nodes, options = {}) {
1100
1140
  const children = (node.childIds ?? []).map((id) => nodeMap.get(id)).filter((c) => Boolean(c));
1101
1141
  if (node.ignored) {
1102
1142
  for (const child of children)
1103
- renderNode(child, depth, parentName);
1143
+ renderNode(child, depth, parentName, parentLeafText);
1104
1144
  return;
1105
1145
  }
1106
- const name = cleanText(node.name?.value);
1146
+ const fullRawName = normalizeWs(node.name?.value);
1147
+ const name = cleanText(fullRawName);
1107
1148
  const value = cleanText(node.value?.value, 100);
1108
1149
  const isInteractive = INTERACTIVE_ROLES.has(role) || getProp(node, "focusable") === true;
1109
1150
  if (role === "RootWebArea" || role === "WebArea") {
1110
1151
  for (const child of children)
1111
- renderNode(child, depth, name);
1152
+ renderNode(child, depth, name, "");
1112
1153
  return;
1113
1154
  }
1114
1155
  if (role === "StaticText") {
1115
- if (includeText && name && name !== parentName) {
1116
- lines.push(`${" ".repeat(depth)}- text: "${name}"`);
1117
- }
1156
+ if (!includeText || !name || name === parentName)
1157
+ return;
1158
+ if (parentLeafText && parentLeafText.includes(fullRawName))
1159
+ return;
1160
+ lines.push(`${" ".repeat(depth)}- text: "${name}"`);
1118
1161
  return;
1119
1162
  }
1120
1163
  const isMeaningful = isInteractive || LANDMARK_AND_STRUCTURE_ROLES.has(role);
1121
1164
  if (!isMeaningful) {
1122
1165
  for (const child of children)
1123
- renderNode(child, depth, parentName);
1166
+ renderNode(child, depth, parentName, parentLeafText);
1124
1167
  return;
1125
1168
  }
1126
1169
  const lineStartIndex = lines.length;
@@ -1170,21 +1213,31 @@ function formatAXTree(nodes, options = {}) {
1170
1213
  const namePart = name ? ` "${name}"` : "";
1171
1214
  const attrPart = attrs.length > 0 ? ` (${attrs.join(", ")})` : "";
1172
1215
  lines.push(`${indent}- ${refPrefix}${role}${namePart}${attrPart}`);
1216
+ const nextLeafText = fullRawName && LEAF_LABELED_ROLES.has(role) ? fullRawName : parentLeafText;
1173
1217
  for (const child of children) {
1174
- renderNode(child, depth + 1, name || parentName);
1218
+ renderNode(child, depth + 1, name || parentName, nextLeafText);
1175
1219
  }
1176
1220
  if (!isInteractive && !name && attrs.length === 0 && lines.length === lineStartIndex + 1) {
1177
1221
  lines.pop();
1178
1222
  }
1179
1223
  }
1180
- renderNode(rootNode, 0, "");
1224
+ renderNode(rootNode, 0, "", "");
1181
1225
  return { lines, refs, nextRefIndex: refCounter };
1182
1226
  }
1183
- function filterSnapshotLines(fullText, search, maxMatches = 25) {
1227
+ function filterSnapshotLines(fullText, search, maxMatches = 40) {
1184
1228
  const allLines = fullText.split("\n");
1185
1229
  const header = allLines[0]?.startsWith("URL:") ? allLines[0] : "";
1186
1230
  const body = header ? allLines.slice(1) : allLines;
1187
- const regex = search instanceof RegExp ? search : new RegExp(escapeRegex(search), "i");
1231
+ let regex;
1232
+ if (search instanceof RegExp) {
1233
+ regex = search;
1234
+ } else {
1235
+ try {
1236
+ regex = new RegExp(search, "i");
1237
+ } catch {
1238
+ regex = new RegExp(escapeRegex(search), "i");
1239
+ }
1240
+ }
1188
1241
  const matchedIndices = /* @__PURE__ */ new Set();
1189
1242
  let count = 0;
1190
1243
  for (let i = 0; i < body.length; i++) {
@@ -2756,7 +2809,16 @@ var ConsoleCollector = class {
2756
2809
  }
2757
2810
  }
2758
2811
  if (options.search !== void 0) {
2759
- const regex = options.search instanceof RegExp ? options.search : new RegExp(options.search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
2812
+ let regex;
2813
+ if (options.search instanceof RegExp) {
2814
+ regex = options.search;
2815
+ } else {
2816
+ try {
2817
+ regex = new RegExp(options.search, "i");
2818
+ } catch {
2819
+ regex = new RegExp(options.search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
2820
+ }
2821
+ }
2760
2822
  list = list.filter((e) => regex.test(e.text) || e.url && regex.test(e.url) || e.stackTrace && regex.test(e.stackTrace));
2761
2823
  }
2762
2824
  this.cursors.set(cursorKey, this.getLatestId());
@@ -2947,7 +3009,16 @@ var NetworkInspector = class {
2947
3009
  list = list.filter((e) => e.resourceType?.toLowerCase() === rt);
2948
3010
  }
2949
3011
  if (options.search !== void 0) {
2950
- const regex = options.search instanceof RegExp ? options.search : new RegExp(options.search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
3012
+ let regex;
3013
+ if (options.search instanceof RegExp) {
3014
+ regex = options.search;
3015
+ } else {
3016
+ try {
3017
+ regex = new RegExp(options.search, "i");
3018
+ } catch {
3019
+ regex = new RegExp(options.search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
3020
+ }
3021
+ }
2951
3022
  list = list.filter((e) => regex.test(e.url) || e.errorText && regex.test(e.errorText));
2952
3023
  }
2953
3024
  const latestTs = this.entries[this.entries.length - 1]?.timestamp ?? Date.now();
@@ -3176,7 +3247,8 @@ function formatStylesAsText(styles) {
3176
3247
  if (styles.inlineStyles.length) {
3177
3248
  lines.push(" element.style {");
3178
3249
  for (const d of styles.inlineStyles) {
3179
- lines.push(` ${d.name}: ${d.value}${d.important ? " !important" : ""};`);
3250
+ const imp = d.important && !/!important\s*$/i.test(d.value) ? " !important" : "";
3251
+ lines.push(` ${d.name}: ${d.value}${imp};`);
3180
3252
  }
3181
3253
  lines.push(" }");
3182
3254
  }
@@ -3185,7 +3257,8 @@ function formatStylesAsText(styles) {
3185
3257
  lines.push(` ${r.selector} {${loc}`);
3186
3258
  for (const d of r.declarations) {
3187
3259
  const strike = d.overridden ? " /* overridden */" : "";
3188
- lines.push(` ${d.name}: ${d.value}${d.important ? " !important" : ""};${strike}`);
3260
+ const imp = d.important && !/!important\s*$/i.test(d.value) ? " !important" : "";
3261
+ lines.push(` ${d.name}: ${d.value}${imp};${strike}`);
3189
3262
  }
3190
3263
  lines.push(" }");
3191
3264
  }
@@ -7136,42 +7209,56 @@ exec ${JSON.stringify(process.execPath)} ${JSON.stringify(nativeHostJs)} "$@"
7136
7209
  }
7137
7210
 
7138
7211
  // src/skill-doc.ts
7139
- var BROWSERPILOT_SKILL_DOC = `# BrowserPilot \u2014 Zero-Click Pure-CDP Browser Control & DevTools Guide
7212
+ var BROWSERPILOT_SKILL_DOC = `# BrowserPilot \u2014 Real Chrome Automation & DevTools Guide
7213
+
7214
+ BrowserPilot controls the user's running Chrome browser (existing logins, cookies, tabs) or a Direct CDP Chromium instance via pure CDP with zero per-tab confirmation clicks.
7215
+
7216
+ ## 1. Choose Mode (MCP vs CLI)
7217
+ - If \`browser_*\` MCP tools are available in this session, prefer calling them directly (screenshots return inline image blocks automatically).
7218
+ - Otherwise use the \`browserpilot\` CLI in the shell.
7219
+ - If a command reports no browser connected, run \`browserpilot doctor\` to diagnose and report clearly.
7140
7220
 
7141
- BrowserPilot controls your real logged-in Chrome browser (existing cookies, logins, extensions) via pure CDP with **zero manual confirmation clicks**.
7221
+ ## 2. Core Workflow
7222
+ 1. **Tabs**: \`browser_tabs\` / \`browserpilot tabs\`, or \`browser_open_tab\` / \`browserpilot open <url> --tab-group <name>\`. Always pass \`--tab <id>\` (\`tabId\`) when multiple tabs are open.
7223
+ 2. **Perceive**:
7224
+ - \`browser_snapshot\` / \`browserpilot snapshot --tab <id> [--search "<regex>"] [--scope "<css>"] [--full]\`
7225
+ - First call returns full AXTree with \`e1\`, \`e2\`... refs + viewport/scroll info; subsequent calls return diffs (pass \`--full\` / \`showDiffSinceLastCall: false\` for full output).
7226
+ - Use \`browser_labeled_screenshot\` / \`browserpilot labeled-screenshot <path>\` when spatial layout or icon-only buttons matter.
7227
+ 3. **Act (trusted CDP input)**:
7228
+ - \`click\`, \`fill\`, \`type\`, \`press_key\`, \`hover\`, \`scroll\`, \`drag\`, \`select_option\`, \`upload_file\`, \`batch\`.
7229
+ - Targets accept refs (\`e5\`), CSS selectors (\`#submit\`), \`role=button[name="Save"]\`, \`label=...\`, \`placeholder=...\`, \`text=...\`, \`>> nth=N\`, or \`pinned\`.
7230
+ 4. **DevTools Debugging**:
7231
+ - \`browser_console\` / \`browserpilot console --level error --since-last\`
7232
+ - \`browser_network\` / \`browserpilot network --failed\` (pass \`requestId\` for headers, timing, initiator stack, body)
7233
+ - \`browser_network_intercept\` \u2014 mock/block API responses via CDP \`Fetch\`
7234
+ - \`browser_styles\` / \`browserpilot styles <target>\` \u2014 clean author CSS rules with \`file:line\` + forced \`:hover\`/\`:focus\`
7235
+ - \`browser_react_info\` / \`browserpilot react <target>\` \u2014 React Fiber component, source \`file:line\`, props
7236
+ - \`browser_debugger\` / \`browser_live_edit\` \u2014 breakpoints, call frames, live JS/CSS patching
7237
+ - \`browser_performance\` / \`browserpilot perf metrics\` \u2014 Web Vitals (LCP/CLS/FCP/TTFB), heap, CPU/trace
7238
+ - \`browser_downloads\`, \`browser_action_recorder\`, \`browser_record\` (MP4/WebM + smart idle speedup)
7142
7239
 
7143
- ## Core Workflow (Fast & Token-Efficient)
7240
+ ## 3. Stateful JS Sandbox (\`browserpilot exec\`)
7241
+ > Important: BrowserPilot is **pure CDP, NOT Playwright** \u2014 do NOT call \`page.locator(...)\`. Use \`t.page.*\` and built-in helpers.
7144
7242
 
7145
- 1. **Discover tabs**: \`browser_tabs\` (or \`browserpilot tabs\`) \u2014 lists all tabs with \`tabId\`, URL, and title.
7146
- 2. **Navigate or pick existing tab**: \`browser_open_tab\` / \`browser_select_tab\` / \`browser_navigate\`. BrowserPilot auto-attaches \`chrome.debugger\` on demand with zero clicks.
7147
- 3. **Perceive the page**:
7148
- - Prefer \`browser_snapshot\` (compact AXTree with \`e1\`, \`e2\`... refs + automatic incremental diffs).
7149
- - Use \`scope\` (CSS selector/ref) or \`search\` on large pages to save tokens.
7150
- - Use \`browser_labeled_screenshot\` (Set-of-Mark overlays) when visual layout matters.
7151
- 4. **Interact with trusted CDP input**:
7152
- - \`browser_click\`, \`browser_fill\`, \`browser_type\`, \`browser_press_key\`, \`browser_select_option\`, \`browser_drag\`, \`browser_upload_file\`.
7153
- - Every action automatically reports newly thrown Console errors and failed Network requests.
7154
- 5. **Debug like Chrome DevTools**:
7155
- - \`browser_console\` (\`sinceLastCall: true\`) \u2014 logs, warnings, uncaught exceptions with stacks.
7156
- - \`browser_network\` (\`failedOnly: true\`, or pass \`requestId\` for headers, timing, JS initiator stack, and response body).
7157
- - \`browser_network_intercept\` \u2014 mock/block API responses via CDP \`Fetch\`.
7158
- - \`browser_styles\` \u2014 matched/inherited CSS rules with \`file:line\` + forced \`:hover\`/\`:focus\`.
7159
- - \`browser_react_info\` \u2014 React Fiber component name, dev source \`file:line\`, hierarchy, props.
7160
- - \`browser_debugger\` \u2014 breakpoints, pause/step, local scope variables, evaluate in call frame.
7161
- - \`browser_live_edit\` \u2014 grep loaded scripts and live-patch JS/CSS in memory.
7162
- - \`browser_performance\` \u2014 Core Web Vitals (LCP/CLS/FCP/TTFB), heap summary, CPU profiler, Tracing insights.
7163
- - \`browser_emulate\` \u2014 viewport, mobile, dark mode, CPU throttling, Slow 3G / offline.
7164
- - \`browser_downloads\` \u2014 configure download folder, list downloads, or wait for a file download to complete with its local path.
7165
- - \`browser_action_recorder\` \u2014 record user clicks/fills/selects/navigations into reusable batch steps, exec JS script, and Agent Skill Markdown.
7166
- - \`browser_record\` \u2014 record MP4/WebM screencast video via \`ffmpeg\` (optional \`audio: true\`) and create smart idle-sped-up demo videos.
7167
- 6. **Multi-step Stateful Sandbox (Playwriter replacement)**:
7168
- - \`browserpilot session new --tab-group docs\` -> returns session ID (e.g. \`1\`)
7169
- - \`browserpilot exec -s 1 -e 'const t = await tabs.open("https://example.com"); console.log(await snapshot({ tab: t }))'\`
7170
- - Available sandbox globals: \`state\`, \`tabs\`, \`snapshot\`, \`screenshot\`, \`screenshotWithLabels\`, \`cleanHTML\`, \`markdown\`, \`inspect\`, \`getLatestLogs\`, \`getNetwork\`, \`getStyles\`, \`getReactInfo\`, \`waitForPageLoad\`, \`waitForSelector\`, \`waitForText\`, \`cdp\`, \`createDemoVideo\`.
7243
+ \`\`\`bash
7244
+ SID=$(browserpilot session new --tab-group work)
7245
+ browserpilot exec -s "$SID" -e '
7246
+ const t = await tabs.open("http://localhost:3000");
7247
+ state.tab = t;
7248
+ await waitForSelector("#email", { tab: t });
7249
+ await t.page.fill("#email", "alice@example.com");
7250
+ await t.page.click("role=button[name=\\"Sign in\\"]");
7251
+ console.log(await snapshot({ tab: t }));
7252
+ '
7253
+ \`\`\`
7171
7254
 
7172
- ## Safety Rules
7173
- - Never wipe profile-wide cookies/cache (BrowserPilot blocks \`Network.clearBrowserCookies\` / \`Network.clearBrowserCache\` automatically; use page-scoped \`browser_cookies\`).
7174
- - Confirm with the user before irreversible actions (payments, deletions, account/security changes, sending public posts).
7255
+ Globals: \`state\`, \`tabs\` (\`list\`, \`open\`, \`use\`, \`current\`, \`close\`), \`snapshot\`, \`screenshot\`, \`screenshotWithLabels\`, \`cleanHTML\`, \`markdown\`, \`inspect\`, \`getLatestLogs\`, \`getNetwork\`, \`getStyles\`, \`getReactInfo\`, \`waitForPageLoad\`, \`waitForSelector\`, \`waitForText\`, \`downloads\`, \`actionRecorder\`, \`cdp\`, \`sleep\`, \`createDemoVideo\`.
7256
+
7257
+ ## 4. Safety & Pitfalls
7258
+ - Confirm with the user before irreversible actions (payments, deletions, account/security changes, public posts).
7259
+ - Never bypass CAPTCHAs, Cloudflare Turnstile, or 2FA/Passkey prompts \u2014 stop and let the user complete them in Chrome.
7260
+ - If \`Another debugger is already attached\` appears, ask the user to close DevTools / detach the other extension on that tab, or open a new tab with \`browserpilot open\`.
7261
+ - Never wipe profile-wide cookies/cache (blocked automatically; use page-scoped \`browser_cookies\`).
7175
7262
  `;
7176
7263
 
7177
7264
  // src/cli.ts
@@ -7308,9 +7395,15 @@ Direct Quick Commands:
7308
7395
  browserpilot open <url> [--tab-group <name>]
7309
7396
  browserpilot close <tabId>
7310
7397
  browserpilot navigate <url> [--tab <id>]
7398
+ browserpilot back | forward | reload [--ignore-cache] [--tab <id>]
7311
7399
  browserpilot snapshot [--tab <id>] [--search <regex>] [--scope <css>] [--full]
7400
+ browserpilot markdown [--search <regex>] [--full] [--tab <id>]
7401
+ browserpilot html [--selector <css>] [--search <regex>] [--full] [--tab <id>]
7312
7402
  browserpilot click <ref|selector> [--tab <id>]
7313
7403
  browserpilot fill <ref|selector> <value> [--tab <id>]
7404
+ browserpilot hover <ref|selector> [--tab <id>]
7405
+ browserpilot scroll [down|up|left|right] [--amount <px>] [--target <ref|sel>] [--tab <id>]
7406
+ browserpilot wait [--selector <css>] [--text <str>] [--ms <N>] [--timeout <ms>] [--tab <id>]
7314
7407
  browserpilot screenshot [outputPath] [--full-page] [--tab <id>]
7315
7408
  browserpilot labeled-screenshot [outputPath] [--tab <id>]
7316
7409
  browserpilot console [--level error] [--search <str>] [--since-last] [--tab <id>]
@@ -7492,7 +7585,13 @@ BrowserPilot Setup (v${BROWSERPILOT_VERSION})`);
7492
7585
  }
7493
7586
  const cliBin = path7.resolve(__dirname3, "cli.js");
7494
7587
  console.log(`
7495
- 4. MCP Server Config (Claude Code / Cursor / Codex / Antigravity):`);
7588
+ 4. Connect Your AI Agent (Choose Option A or B \u2014 setup never modifies your agent configs):`);
7589
+ console.log(`
7590
+ Option A \u2014 Agent Skill + CLI (install only where you want):`);
7591
+ console.log(` npx skills add xy-tuoren/browserpilot`);
7592
+ console.log(` (or print skill instructions with: browserpilot skill)`);
7593
+ console.log(`
7594
+ Option B \u2014 MCP Server (43 native tools + direct screenshot images):`);
7496
7595
  console.log(
7497
7596
  JSON.stringify(
7498
7597
  {
@@ -7685,6 +7784,22 @@ BrowserPilot Setup (v${BROWSERPILOT_VERSION})`);
7685
7784
  case "goto":
7686
7785
  printToolOutput(await client.callTool("browser_navigate", { url: positional[1], tabId, sessionId }));
7687
7786
  return;
7787
+ case "back":
7788
+ printToolOutput(await client.callTool("browser_history", { action: "back", tabId, sessionId }));
7789
+ return;
7790
+ case "forward":
7791
+ printToolOutput(await client.callTool("browser_history", { action: "forward", tabId, sessionId }));
7792
+ return;
7793
+ case "reload":
7794
+ printToolOutput(
7795
+ await client.callTool("browser_history", {
7796
+ action: "reload",
7797
+ ignoreCache: Boolean(flags["ignore-cache"]),
7798
+ tabId,
7799
+ sessionId
7800
+ })
7801
+ );
7802
+ return;
7688
7803
  case "snapshot":
7689
7804
  printToolOutput(
7690
7805
  await client.callTool("browser_snapshot", {
@@ -7696,9 +7811,60 @@ BrowserPilot Setup (v${BROWSERPILOT_VERSION})`);
7696
7811
  })
7697
7812
  );
7698
7813
  return;
7814
+ case "markdown":
7815
+ printToolOutput(
7816
+ await client.callTool("browser_markdown", {
7817
+ tabId,
7818
+ sessionId,
7819
+ search: typeof flags.search === "string" ? flags.search : void 0,
7820
+ showDiffSinceLastCall: flags.full ? false : void 0
7821
+ })
7822
+ );
7823
+ return;
7824
+ case "html":
7825
+ printToolOutput(
7826
+ await client.callTool("browser_clean_html", {
7827
+ tabId,
7828
+ sessionId,
7829
+ selector: typeof flags.selector === "string" ? flags.selector : void 0,
7830
+ search: typeof flags.search === "string" ? flags.search : void 0,
7831
+ showDiffSinceLastCall: flags.full ? false : void 0,
7832
+ includeStyles: Boolean(flags["include-styles"])
7833
+ })
7834
+ );
7835
+ return;
7699
7836
  case "click":
7700
7837
  printToolOutput(await client.callTool("browser_click", { target: positional[1], tabId, sessionId }));
7701
7838
  return;
7839
+ case "hover":
7840
+ printToolOutput(await client.callTool("browser_hover", { target: positional[1], tabId, sessionId }));
7841
+ return;
7842
+ case "scroll": {
7843
+ const dir = positional[1];
7844
+ const direction = dir === "up" || dir === "down" || dir === "left" || dir === "right" ? dir : "down";
7845
+ printToolOutput(
7846
+ await client.callTool("browser_scroll", {
7847
+ direction,
7848
+ amount: typeof flags.amount === "string" ? Number(flags.amount) : void 0,
7849
+ target: typeof flags.target === "string" ? flags.target : void 0,
7850
+ tabId,
7851
+ sessionId
7852
+ })
7853
+ );
7854
+ return;
7855
+ }
7856
+ case "wait":
7857
+ printToolOutput(
7858
+ await client.callTool("browser_wait", {
7859
+ selector: typeof flags.selector === "string" ? flags.selector : void 0,
7860
+ text: typeof flags.text === "string" ? flags.text : void 0,
7861
+ ms: typeof flags.ms === "string" ? Number(flags.ms) : void 0,
7862
+ timeoutMs: typeof flags.timeout === "string" ? Number(flags.timeout) : void 0,
7863
+ tabId,
7864
+ sessionId
7865
+ })
7866
+ );
7867
+ return;
7702
7868
  case "fill":
7703
7869
  printToolOutput(await client.callTool("browser_fill", { target: positional[1], value: positional[2] ?? "", tabId, sessionId }));
7704
7870
  return;