




















@@ -10,6 +10,24 @@ import {
1010type SnapshotResult,
1111} from "./core-api.js";
121213+function parseOptionalIntegerOption(
14+value: string | undefined,
15+label: string,
16+opts: { min: number },
17+): number | undefined {
18+if (value === undefined) {
19+return undefined;
20+}
21+const raw = value.trim();
22+const parsed = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
23+if (!Number.isSafeInteger(parsed) || parsed < opts.min) {
24+defaultRuntime.error(danger(`Invalid ${label}: must be an integer >= ${opts.min}`));
25+defaultRuntime.exit(1);
26+return undefined;
27+}
28+return parsed;
29+}
30+1331export function registerBrowserInspectCommands(
1432browser: Command,
1533parentOpts: (cmd: Command) => BrowserParentOpts,
@@ -60,12 +78,12 @@ export function registerBrowserInspectCommands(
6078.description("Capture a snapshot (default: ai; aria is the accessibility tree)")
6179.option("--format <aria|ai>", "Snapshot format (default: ai)", "ai")
6280.option("--target-id <id>", "CDP target id (or unique prefix)")
63-.option("--limit <n>", "Max nodes (default: 500/800)", (v: string) => Number(v))
81+.option("--limit <n>", "Max nodes (default: 500/800)")
6482.option("--mode <efficient>", "Snapshot preset (efficient)")
6583.option("--efficient", "Use the efficient snapshot preset", false)
6684.option("--interactive", "Role snapshot: interactive elements only", false)
6785.option("--compact", "Role snapshot: compact output", false)
68-.option("--depth <n>", "Role snapshot: max depth", (v: string) => Number(v))
86+.option("--depth <n>", "Role snapshot: max depth")
6987.option("--selector <sel>", "Role snapshot: scope to CSS selector")
7088.option("--frame <sel>", "Role snapshot: scope to an iframe selector")
7189.option("--labels", "Include viewport label overlay screenshot", false)
@@ -85,14 +103,22 @@ export function registerBrowserInspectCommands(
85103 ? "efficient"
86104 : undefined;
87105const mode = opts.efficient === true || opts.mode === "efficient" ? "efficient" : configMode;
106+const limit = parseOptionalIntegerOption(opts.limit, "--limit", { min: 1 });
107+const depth = parseOptionalIntegerOption(opts.depth, "--depth", { min: 0 });
108+if (
109+(opts.limit !== undefined && limit === undefined) ||
110+(opts.depth !== undefined && depth === undefined)
111+) {
112+return;
113+}
88114try {
89115const query: Record<string, string | number | boolean | undefined> = {
90116 format,
91117targetId: normalizeOptionalString(opts.targetId),
92-limit: Number.isFinite(opts.limit) ? opts.limit : undefined,
118+ limit,
93119interactive: opts.interactive ? true : undefined,
94120compact: opts.compact ? true : undefined,
95-depth: Number.isFinite(opts.depth) ? opts.depth : undefined,
121+ depth,
96122selector: normalizeOptionalString(opts.selector),
97123frame: normalizeOptionalString(opts.frame),
98124labels: opts.labels ? true : undefined,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。