UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 3.73 kB
import { l as normalizeOptionalString } from "./string-coerce-1VuiLaaR.mjs"; import { p as shortenHomePath } from "./utils-CitNzLyF.mjs"; import "./string-coerce-runtime-BbIJhy7G.mjs"; import "./text-utility-runtime-BB0hWeEg.mjs"; import { l as runBrowserCliRequest, o as printBrowserList, t as BROWSER_TAB_REFERENCE_HELP } from "./browser-cli-shared-Un7moqdm.mjs"; //#region extensions/browser/src/cli/browser-cli-debug.ts 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 runBrowserCliRequest({ parent: parentOpts(cmd), path: "/highlight", body: { ref: ref.trim(), targetId: normalizeOptionalString(opts.targetId) }, successMessage: `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 runBrowserCliRequest({ parent: parentOpts(cmd), method: "GET", path: "/errors", query: { targetId: normalizeOptionalString(opts.targetId), clear: Boolean(opts.clear) }, print: (result) => printBrowserList(result.errors, "No page errors.", (e) => `${e.timestamp} ${e.name ? `${e.name}: ` : ""}${e.message}`) }); }); 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 runBrowserCliRequest({ parent: parentOpts(cmd), method: "GET", path: "/requests", query: { targetId: normalizeOptionalString(opts.targetId), filter: normalizeOptionalString(opts.filter), clear: Boolean(opts.clear) }, print: (result) => printBrowserList(result.requests, "No requests recorded.", (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}`; }) }); }); 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 runBrowserCliRequest({ parent: parentOpts(cmd), path: "/trace/start", body: { targetId: normalizeOptionalString(opts.targetId), screenshots: Boolean(opts.screenshots), snapshots: Boolean(opts.snapshots), sources: Boolean(opts.sources) }, successMessage: "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 runBrowserCliRequest({ parent: parentOpts(cmd), path: "/trace/stop", body: { targetId: normalizeOptionalString(opts.targetId), path: normalizeOptionalString(opts.out) }, successMessage: (result) => `TRACE:${shortenHomePath(result.path)}` }); }); } //#endregion export { registerBrowserDebugCommands };