UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

120 lines (119 loc) 5.3 kB
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { r as defaultRuntime } from "./runtime-CF2WjnNZ.js"; import { m as shortenHomePath } from "./utils-P__uGsPB.js"; import "./string-coerce-runtime-GQa0ehRA.js"; import "./core-api-zb8NP8I7.js"; import { c as resolveBrowserProfileQuery, l as runBrowserCliCommand, n as callBrowserRequest, s as printBrowserJsonResult, t as BROWSER_TAB_REFERENCE_HELP } from "./browser-cli-shared-Co4TmZyV.js"; //#region extensions/browser/src/cli/browser-cli-debug.ts async function withDebugContext(cmd, parentOpts, action) { const parent = parentOpts(cmd); await runBrowserCliCommand(() => action({ parent, profile: parent.browserProfile })); } function resolveDebugQuery(params) { return { targetId: normalizeOptionalString(params.targetId), filter: normalizeOptionalString(params.filter), clear: Boolean(params.clear), profile: params.profile }; } /** Registers Browser debugging and trace commands. */ function registerBrowserDebugCommands(browser, parentOpts) { browser.command("highlight").description("Highlight an element by ref").argument("<ref>", "Ref id from snapshot").option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (ref, opts, cmd) => { await withDebugContext(cmd, parentOpts, async ({ parent, profile }) => { const result = await callBrowserRequest(parent, { method: "POST", path: "/highlight", query: resolveBrowserProfileQuery(profile), body: { ref: ref.trim(), targetId: normalizeOptionalString(opts.targetId) } }); if (printBrowserJsonResult(parent, result)) return; defaultRuntime.log(`highlighted ${ref.trim()}`); }); }); browser.command("errors").description("Get recent page errors").option("--clear", "Clear stored errors after reading", false).option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (opts, cmd) => { await withDebugContext(cmd, parentOpts, async ({ parent, profile }) => { const result = await callBrowserRequest(parent, { method: "GET", path: "/errors", query: resolveDebugQuery({ targetId: opts.targetId, clear: opts.clear, profile }) }); if (printBrowserJsonResult(parent, result)) return; if (!result.errors.length) { defaultRuntime.log("No page errors."); return; } defaultRuntime.log(result.errors.map((e) => `${e.timestamp} ${e.name ? `${e.name}: ` : ""}${e.message}`).join("\n")); }); }); browser.command("requests").description("Get recent network requests (best-effort)").option("--filter <text>", "Only show URLs that contain this substring").option("--clear", "Clear stored requests after reading", false).option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (opts, cmd) => { await withDebugContext(cmd, parentOpts, async ({ parent, profile }) => { const result = await callBrowserRequest(parent, { method: "GET", path: "/requests", query: resolveDebugQuery({ targetId: opts.targetId, filter: opts.filter, clear: opts.clear, profile }) }); if (printBrowserJsonResult(parent, result)) return; if (!result.requests.length) { defaultRuntime.log("No requests recorded."); return; } defaultRuntime.log(result.requests.map((r) => { const status = typeof r.status === "number" ? ` ${r.status}` : ""; const ok = r.ok === true ? " ok" : r.ok === false ? " fail" : ""; const fail = r.failureText ? ` (${r.failureText})` : ""; return `${r.timestamp} ${r.method}${status}${ok} ${r.url}${fail}`; }).join("\n")); }); }); const trace = browser.command("trace").description("Record a Playwright trace"); trace.command("start").description("Start trace recording").option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).option("--no-screenshots", "Disable screenshots").option("--no-snapshots", "Disable snapshots").option("--sources", "Include sources (bigger traces)", false).action(async (opts, cmd) => { await withDebugContext(cmd, parentOpts, async ({ parent, profile }) => { const result = await callBrowserRequest(parent, { method: "POST", path: "/trace/start", query: resolveBrowserProfileQuery(profile), body: { targetId: normalizeOptionalString(opts.targetId), screenshots: Boolean(opts.screenshots), snapshots: Boolean(opts.snapshots), sources: Boolean(opts.sources) } }); if (printBrowserJsonResult(parent, result)) return; defaultRuntime.log("trace started"); }); }); trace.command("stop").description("Stop trace recording and write a .zip").option("--out <path>", "Output path within openclaw temp dir (e.g. trace.zip or /tmp/openclaw/trace.zip)").option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (opts, cmd) => { await withDebugContext(cmd, parentOpts, async ({ parent, profile }) => { const result = await callBrowserRequest(parent, { method: "POST", path: "/trace/stop", query: resolveBrowserProfileQuery(profile), body: { targetId: normalizeOptionalString(opts.targetId), path: normalizeOptionalString(opts.out) } }); if (printBrowserJsonResult(parent, result)) return; defaultRuntime.log(`TRACE:${shortenHomePath(result.path)}`); }); }); } //#endregion export { registerBrowserDebugCommands };