aboutsummaryrefslogtreecommitdiff
path: root/src/setup.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-04-29 01:38:17 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-04-29 01:38:17 +0530
commit63b16957587fe20566129ffc5191f66f24a70872 (patch)
tree8a40fa38e1ae5b4309b1e38d7a3779321f15db4e /src/setup.ts
parent5317b32976edce3ab8e2f11d7fb4ff3f16dcac6f (diff)
Replace socket daemon with direct CDP WebSocket connection
Drops the Unix socket subprocess in favor of talking CDP directly over WebSocket from the extension. Removes the protocol's send/health helpers, simplifies setup to just verifying Chrome's remote debugging port, and tightens types in dynamic-tools. Bumps Node engine to >=22 and adds the ws dependency.
Diffstat (limited to 'src/setup.ts')
-rw-r--r--src/setup.ts113
1 files changed, 16 insertions, 97 deletions
diff --git a/src/setup.ts b/src/setup.ts
index 839a540..f99e9d9 100644
--- a/src/setup.ts
+++ b/src/setup.ts
@@ -1,18 +1,15 @@
/**
- * Setup command — guides the user through installing and connecting
- * browser-harness to their Chrome browser.
+ * Setup command — verifies Chrome is running with remote debugging
+ * and connects the pi agent to it.
*/
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
import { execSync } from "node:child_process";
-import { existsSync } from "node:fs";
-import { homedir } from "node:os";
-import { join } from "node:path";
import type { BrowserDaemon } from "./daemon";
export function registerSetupCommand(pi: ExtensionAPI, daemon: BrowserDaemon): void {
pi.registerCommand("browser-setup", {
- description: "Install and connect browser-harness to Chrome",
+ description: "Connect pi to your Chrome browser",
handler: async (_args, ctx) => {
await runSetup(ctx, daemon);
},
@@ -20,30 +17,9 @@ export function registerSetupCommand(pi: ExtensionAPI, daemon: BrowserDaemon): v
}
async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise<void> {
- ctx.ui.notify("browser-harness setup: checking installation...", "info");
+ ctx.ui.notify("browser setup: checking Chrome...", "info");
- // Step 1: Check for browser-harness installation
- const bhInstalled = await checkBrowserHarnessInstalled();
- if (!bhInstalled) {
- ctx.ui.notify(
- "browser-harness not found. Installing...",
- "warning",
- );
- const installed = await installBrowserHarness(ctx);
- if (!installed) {
- ctx.ui.notify(
- "Installation failed. Please install manually:\n" +
- " git clone https://github.com/browser-use/browser-harness ~/Developer/browser-harness\n" +
- " cd ~/Developer/browser-harness && uv sync",
- "error",
- );
- return;
- }
- }
-
- ctx.ui.notify("browser-harness found ✓", "info");
-
- // Step 2: Check Chrome is running
+ // Step 1: Check Chrome is running
const chromeRunning = checkChromeRunning();
if (!chromeRunning) {
ctx.ui.notify(
@@ -54,23 +30,26 @@ async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise<v
}
ctx.ui.notify("Chrome is running ✓", "info");
- // Step 3: Try to start the daemon
- ctx.ui.notify("Connecting to Chrome...", "info");
+ // Step 2: Try to connect to Chrome DevTools
+ ctx.ui.notify("Connecting to Chrome DevTools...", "info");
try {
await daemon.start();
- ctx.ui.notify("Daemon connected ✓", "info");
+ ctx.ui.notify("Connected to Chrome ✓", "info");
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
const lower = msg.toLowerCase();
if (
lower.includes("devtoolsactiveport") ||
- lower.includes("remote debugging")
+ lower.includes("remote debugging") ||
+ lower.includes("econnrefused") ||
+ lower.includes("cannot reach chrome devtools")
) {
ctx.ui.notify(
"Chrome remote debugging needs to be enabled.\n\n" +
- "Start Chrome with: --remote-debugging-port=9222\n" +
- "Then run /browser-setup again.",
+ "Open chrome://inspect/#remote-debugging in your browser, tick the\n" +
+ "\"Discover network targets\" / Allow checkbox, then run /browser-setup again.\n\n" +
+ "Or set BU_CDP_WS to a remote browser WebSocket URL.",
"warning",
);
return;
@@ -80,10 +59,10 @@ async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise<v
return;
}
- // Step 4: Verify with test navigation
+ // Step 3: Verify with test navigation
ctx.ui.notify("Testing browser control...", "info");
try {
- await daemon.newTab("https://github.com/browser-use/browser-harness");
+ await daemon.newTab("https://github.com");
const info = await daemon.getPageInfo();
if ("dialog" in info) {
await daemon.cdp("Page.handleJavaScriptDialog", { accept: true });
@@ -100,66 +79,6 @@ async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise<v
}
}
-// ── Helpers ──────────────────────────────────────────────────────────────────
-
-async function checkBrowserHarnessInstalled(): Promise<boolean> {
- const searchPaths = [
- join(homedir(), "Developer", "browser-harness"),
- join(homedir(), "src", "browser-harness"),
- join(homedir(), "browser-harness"),
- join(homedir(), "dev", "browser-harness"),
- join(homedir(), "Projects", "browser-harness"),
- process.cwd(),
- ];
-
- for (const dir of searchPaths) {
- if (
- existsSync(join(dir, "daemon.py")) &&
- existsSync(join(dir, "helpers.py"))
- ) {
- return true;
- }
- }
-
- // Check if uv tool is installed globally
- try {
- execSync("uv tool list 2>/dev/null | grep browser-harness", { timeout: 5000 });
- return true;
- } catch {
- // not found via uv
- }
-
- return false;
-}
-
-async function installBrowserHarness(ctx: ExtensionContext): Promise<boolean> {
- // Try uv tool install
- try {
- ctx.ui.notify("Installing browser-harness via uv...", "info");
- execSync("uv tool install browser-harness", {
- timeout: 60_000,
- stdio: "pipe",
- });
- return true;
- } catch {
- // uv install failed
- }
-
- // Try git clone
- try {
- const targetDir = join(homedir(), "Developer", "browser-harness");
- ctx.ui.notify(`Cloning browser-harness to ${targetDir}...`, "info");
- execSync(
- `git clone https://github.com/browser-use/browser-harness "${targetDir}"`,
- { timeout: 30_000, stdio: "pipe" },
- );
- execSync("uv sync", { cwd: targetDir, timeout: 60_000, stdio: "pipe" });
- return true;
- } catch {
- return false;
- }
-}
-
function checkChromeRunning(): boolean {
try {
if (process.platform === "darwin" || process.platform === "linux") {