refactor(cli): dedupe browser debug and download opts

This commit is contained in:
Peter Steinberger
2026-02-18 23:33:01 +00:00
parent 0048af4e2d
commit 3f621d13ff
2 changed files with 36 additions and 16 deletions

View File

@@ -12,6 +12,20 @@ function runBrowserDebug(action: () => Promise<void>) {
});
}
function resolveDebugQuery(params: {
targetId?: unknown;
clear?: unknown;
profile?: string;
filter?: unknown;
}) {
return {
targetId: typeof params.targetId === "string" ? params.targetId.trim() || undefined : undefined,
filter: typeof params.filter === "string" ? params.filter.trim() || undefined : undefined,
clear: Boolean(params.clear),
profile: params.profile,
};
}
export function registerBrowserDebugCommands(
browser: Command,
parentOpts: (cmd: Command) => BrowserParentOpts,
@@ -62,11 +76,11 @@ export function registerBrowserDebugCommands(
{
method: "GET",
path: "/errors",
query: {
targetId: opts.targetId?.trim() || undefined,
clear: Boolean(opts.clear),
query: resolveDebugQuery({
targetId: opts.targetId,
clear: opts.clear,
profile,
},
}),
},
{ timeoutMs: 20000 },
);
@@ -110,12 +124,12 @@ export function registerBrowserDebugCommands(
{
method: "GET",
path: "/requests",
query: {
targetId: opts.targetId?.trim() || undefined,
filter: opts.filter?.trim() || undefined,
clear: Boolean(opts.clear),
query: resolveDebugQuery({
targetId: opts.targetId,
filter: opts.filter,
clear: opts.clear,
profile,
},
}),
},
{ timeoutMs: 20000 },
);