feat(browser): copy extension path to clipboard

This commit is contained in:
Peter Steinberger
2026-01-15 06:17:56 +00:00
parent 375304bf13
commit 44a237b637
8 changed files with 85 additions and 25 deletions

View File

@@ -20,10 +20,12 @@
- Config/Doctor: remove legacy Clawdis env fallbacks and config/service migrations (Clawdbot-only). - Config/Doctor: remove legacy Clawdis env fallbacks and config/service migrations (Clawdbot-only).
- Browser: add Chrome extension relay takeover mode (toolbar button), plus `clawdbot browser extension install/path` and remote browser control via `clawdbot browser serve` + `browser.controlToken`. - Browser: add Chrome extension relay takeover mode (toolbar button), plus `clawdbot browser extension install/path` and remote browser control via `clawdbot browser serve` + `browser.controlToken`.
- CLI/Docs: add per-command CLI doc pages and link them from `clawdbot <command> --help`. - CLI/Docs: add per-command CLI doc pages and link them from `clawdbot <command> --help`.
- Browser: copy the installed Chrome extension path to clipboard after `clawdbot browser extension install/path`.
### Fixes ### Fixes
- Browser: add tests for snapshot labels/efficient query params and labeled image responses. - Browser: add tests for snapshot labels/efficient query params and labeled image responses.
- macOS: ensure launchd log directory exists with a test-only override. (#909) — thanks @roshanasingh4. - macOS: ensure launchd log directory exists with a test-only override. (#909) — thanks @roshanasingh4.
- Packaging: run `pnpm build` on `prepack` so npm publishes include fresh `dist/` output.
- Telegram: register dock native commands with underscores to avoid `BOT_COMMAND_INVALID` (#929, fixes #901) — thanks @grp06. - Telegram: register dock native commands with underscores to avoid `BOT_COMMAND_INVALID` (#929, fixes #901) — thanks @grp06.
- Google: downgrade unsigned thinking blocks before send to avoid missing signature errors. - Google: downgrade unsigned thinking blocks before send to avoid missing signature errors.
- Agents: make user time zone and 24-hour time explicit in the system prompt. (#859) — thanks @CashWilliams. - Agents: make user time zone and 24-hour time explicit in the system prompt. (#859) — thanks @CashWilliams.

View File

@@ -61,6 +61,7 @@
"scripts": { "scripts": {
"dev": "tsx src/entry.ts", "dev": "tsx src/entry.ts",
"postinstall": "node scripts/postinstall.js", "postinstall": "node scripts/postinstall.js",
"prepack": "pnpm build",
"docs:list": "tsx scripts/docs-list.ts", "docs:list": "tsx scripts/docs-list.ts",
"docs:bin": "bun build scripts/docs-list.ts --compile --outfile bin/docs-list", "docs:bin": "bun build scripts/docs-list.ts --compile --outfile bin/docs-list",
"docs:dev": "cd docs && mint dev", "docs:dev": "cd docs && mint dev",

View File

@@ -2,7 +2,22 @@ import fs from "node:fs";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { describe, expect, it } from "vitest"; import { describe, expect, it, vi } from "vitest";
const copyToClipboard = vi.fn();
const runtime = {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(),
};
vi.mock("../infra/clipboard.js", () => ({
copyToClipboard,
}));
vi.mock("../runtime.js", () => ({
defaultRuntime: runtime,
}));
describe("browser extension install", () => { describe("browser extension install", () => {
it("installs into the state dir (never node_modules)", async () => { it("installs into the state dir (never node_modules)", async () => {
@@ -16,4 +31,37 @@ describe("browser extension install", () => {
expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true); expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true);
expect(result.path.includes("node_modules")).toBe(false); expect(result.path.includes("node_modules")).toBe(false);
}); });
it("copies extension path to clipboard", async () => {
const prev = process.env.CLAWDBOT_STATE_DIR;
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-ext-path-"));
process.env.CLAWDBOT_STATE_DIR = tmp;
try {
copyToClipboard.mockReset();
copyToClipboard.mockResolvedValue(true);
runtime.log.mockReset();
runtime.error.mockReset();
runtime.exit.mockReset();
const dir = path.join(tmp, "browser", "chrome-extension");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, "manifest.json"), JSON.stringify({ manifest_version: 3 }));
vi.resetModules();
const { Command } = await import("commander");
const { registerBrowserExtensionCommands } = await import("./browser-cli-extension.js");
const program = new Command();
const browser = program.command("browser").option("--json", false);
registerBrowserExtensionCommands(browser, (cmd) => cmd.parent?.opts?.() as { json?: boolean });
await program.parseAsync(["browser", "extension", "path"], { from: "user" });
expect(copyToClipboard).toHaveBeenCalledWith(dir);
} finally {
if (prev === undefined) delete process.env.CLAWDBOT_STATE_DIR;
else process.env.CLAWDBOT_STATE_DIR = prev;
}
});
}); });

View File

@@ -6,6 +6,7 @@ import type { Command } from "commander";
import { STATE_DIR_CLAWDBOT } from "../config/paths.js"; import { STATE_DIR_CLAWDBOT } from "../config/paths.js";
import { danger, info } from "../globals.js"; import { danger, info } from "../globals.js";
import { copyToClipboard } from "../infra/clipboard.js";
import { defaultRuntime } from "../runtime.js"; import { defaultRuntime } from "../runtime.js";
import { movePathToTrash } from "../browser/trash.js"; import { movePathToTrash } from "../browser/trash.js";
import { formatDocsLink } from "../terminal/links.js"; import { formatDocsLink } from "../terminal/links.js";
@@ -76,9 +77,11 @@ export function registerBrowserExtensionCommands(
return; return;
} }
defaultRuntime.log(installed.path); defaultRuntime.log(installed.path);
const copied = await copyToClipboard(installed.path).catch(() => false);
defaultRuntime.error( defaultRuntime.error(
info( info(
[ [
copied ? "Copied to clipboard." : "Copy to clipboard unavailable.",
"Next:", "Next:",
`- Chrome → chrome://extensions → enable “Developer mode”`, `- Chrome → chrome://extensions → enable “Developer mode”`,
`- “Load unpacked” → select: ${installed.path}`, `- “Load unpacked” → select: ${installed.path}`,
@@ -93,7 +96,7 @@ export function registerBrowserExtensionCommands(
ext ext
.command("path") .command("path")
.description("Print the path to the installed Chrome extension (load unpacked)") .description("Print the path to the installed Chrome extension (load unpacked)")
.action((_opts, cmd) => { .action(async (_opts, cmd) => {
const parent = parentOpts(cmd); const parent = parentOpts(cmd);
const dir = installedExtensionRootDir(); const dir = installedExtensionRootDir();
if (!hasManifest(dir)) { if (!hasManifest(dir)) {
@@ -112,5 +115,7 @@ export function registerBrowserExtensionCommands(
return; return;
} }
defaultRuntime.log(dir); defaultRuntime.log(dir);
const copied = await copyToClipboard(dir).catch(() => false);
if (copied) defaultRuntime.error(info("Copied to clipboard."));
}); });
} }

View File

@@ -22,6 +22,9 @@ vi.mock("./onboard-helpers.js", () => ({
detectBrowserOpenSupport: mocks.detectBrowserOpenSupport, detectBrowserOpenSupport: mocks.detectBrowserOpenSupport,
openUrl: mocks.openUrl, openUrl: mocks.openUrl,
formatControlUiSshHint: mocks.formatControlUiSshHint, formatControlUiSshHint: mocks.formatControlUiSshHint,
}));
vi.mock("../infra/clipboard.js", () => ({
copyToClipboard: mocks.copyToClipboard, copyToClipboard: mocks.copyToClipboard,
})); }));

View File

@@ -1,8 +1,8 @@
import { readConfigFileSnapshot, resolveGatewayPort } from "../config/config.js"; import { readConfigFileSnapshot, resolveGatewayPort } from "../config/config.js";
import { copyToClipboard } from "../infra/clipboard.js";
import type { RuntimeEnv } from "../runtime.js"; import type { RuntimeEnv } from "../runtime.js";
import { defaultRuntime } from "../runtime.js"; import { defaultRuntime } from "../runtime.js";
import { import {
copyToClipboard,
detectBrowserOpenSupport, detectBrowserOpenSupport,
formatControlUiSshHint, formatControlUiSshHint,
openUrl, openUrl,

View File

@@ -231,28 +231,6 @@ export async function openUrl(url: string): Promise<boolean> {
} }
} }
export async function copyToClipboard(value: string): Promise<boolean> {
const attempts: Array<{ argv: string[] }> = [
{ argv: ["pbcopy"] },
{ argv: ["xclip", "-selection", "clipboard"] },
{ argv: ["wl-copy"] },
{ argv: ["clip.exe"] }, // WSL / Windows
{ argv: ["powershell", "-NoProfile", "-Command", "Set-Clipboard"] },
];
for (const attempt of attempts) {
try {
const result = await runCommandWithTimeout(attempt.argv, {
timeoutMs: 3_000,
input: value,
});
if (result.code === 0 && !result.killed) return true;
} catch {
// keep trying the next fallback
}
}
return false;
}
export async function ensureWorkspaceAndSessions( export async function ensureWorkspaceAndSessions(
workspaceDir: string, workspaceDir: string,
runtime: RuntimeEnv, runtime: RuntimeEnv,

23
src/infra/clipboard.ts Normal file
View File

@@ -0,0 +1,23 @@
import { runCommandWithTimeout } from "../process/exec.js";
export async function copyToClipboard(value: string): Promise<boolean> {
const attempts: Array<{ argv: string[] }> = [
{ argv: ["pbcopy"] },
{ argv: ["xclip", "-selection", "clipboard"] },
{ argv: ["wl-copy"] },
{ argv: ["clip.exe"] }, // WSL / Windows
{ argv: ["powershell", "-NoProfile", "-Command", "Set-Clipboard"] },
];
for (const attempt of attempts) {
try {
const result = await runCommandWithTimeout(attempt.argv, {
timeoutMs: 3_000,
input: value,
});
if (result.code === 0 && !result.killed) return true;
} catch {
// keep trying the next fallback
}
}
return false;
}