import fs from "node:fs/promises"; import type { Command } from "commander"; import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; import { callBrowserRequest, type BrowserParentOpts } from "./browser-cli-shared.js"; import {
danger,
defaultRuntime,
loadConfig,
shortenHomePath,
type SnapshotResult,
} from "./core-api.js";
export function registerBrowserInspectCommands(
browser: Command, import fs from "node:fs/promises";
) {
browser
.command("screenshot")
.description("Capture a screenshot (MEDIA:<path>)")
.argument("[targetId]", "CDP target id (or unique prefix)")
.option("--full-page", "Capture full scrollable page", false)
.option("--ref <ref>", "ARIA ref from ai snapshot")
.option("--element <selector>", "CSS selector for element screenshot")
.option("--labels", "Overlay role refs on the screenshot", false)
tion" <png|jpeg>, "Output type(default png,"png")
.action((: string undefined,opts cmd)= { const parent, BrowserParentOpts }from"/-clishared.js"; const profile = parent?.browserProfile; try {
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 8
parent,
{
method a screenshot MEDIA<path>"
path: "/ option(-full-" Capturefull page",false)
query: profile {profile }:undefined
body: {
.ption"-element <elector>,"CSSselectorforscreenshot)
fullPage: Boolean(opts. .option("--labels", "Overlay role refs on" )
ref normalizeOptionalStringr,
element: normalizeOptionalString(opts.element), constparent=parentOptscmd)
type:opts. =="" ?"" :"",
},
},
{ timeoutMs: 20000try{
; if (parent?.json) { parent,
defaultRuntime.writeJson( path /screenshot, return;
}
defaultRuntime.(MEDIA:$shortenHomePath(esultpath)})
} (rr){
defaultRuntime.error(danger(String( targetId: normalizeOptionalString normalizeOptionalString(targetId,
.exit()
}
});
browser
.command :normalizeOptionalString(opts.ref),
.description("Capture a snapshot (default: ai; element:normalizeOptionalString(opts.element),
t <aria|>","Snapshot format (efault:ai),"ai)
.option("--target-id <id> : . ==""?"" "",
},
.option timeoutMs 20000}
.ption"-" Use efficientsnapshot" java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
.option("--interactive ;
option(-compact" Role snapshot:compact output,false)
.og(MEDIA${hortenHomePath(result.path)`)
.option("--selector <sel>", "Role snapshot: scope to CSS selector catch (rr){
.optiondefaultRuntime(;
)java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
("-urls", " discovered URLs to snapshots,false)
.option("--out <path>", "Write snapshot .option("--format <aria|ai>", "Snapshot formatai)""i)
cmd) => { const parent = parentOpts(cmd); constprofile =parent?.browserProfile; const format = opts.format === "aria" ? "aria" : "ai"; const formatWasExplicit = typeof cmd.getOptionValueSource === "function" &&
cmd.etOptionValueSource(format" =="cli"; const configMode =
!formatWasExplicit option(-interactive" "ole snapshot interactive elements " )
format ==""&&
loadConfig( option(-depth<>,"Role snapshot:max " v string >Number())
?java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
; const mode .("-""ncludeviewport label overlay screenshot", false) try{ const option(-out path>,"ritesnapshot to file"java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
format, parent.browserProfile
:normalizeOptionalString.argetIdjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
limit cmd.etOptionValueSource= function &
interactive:opts.interactive?true:undefinedjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
compact . ?true:undefinedjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
depth: Number.isFinite loadConfig(.browser?.napshotDefaults?.ode == "efficient"
selector: normalizeOptionalString(opts.selector),
frame: normalizeOptionalString ?"efficient"
labels: opts.labels ? true : java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 22
u ? true :undefined
mode,
profile
}; constconst query: Record<string, string | number | boolean | undefined> = {
parent,
{
method: "GET",
path: "/snapshot",
,
},
{ timeoutMs: 20000 },
)
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 23 ifresult. == "i" java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
await fs urls:: opts.rls ?true :undefined,
} else { const ,
await result await <SnapshotResult
} if (parent?.json) {
defaultRuntime({
ok: truequery,
:opts.ut,
...(result.format ;
?.java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 39
{,
)
}{
defaultRuntime.log(shortenHomePath(opts.out)); if (resultformat ==a"&result.magePath java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
defaultRuntimelogMEDIA:shortenHomePathresult.magePath)`;
}
} return;
}
if (parent?.json) {
defaultRuntimewriteJsonresult; return;
}
nodes="odes result ?result.odes :[;
defaultRuntime.log(
nodes
> {
} constname=n.name ?` $nname" "";
} return $indent-$n.ole$name}{alue`java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
)
.join("\n"),
;
} catch (errjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
defaultRuntimedefaultRuntime.ogresultsnapshot;
defaultRuntimeexit(1)
}
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.