diff --git a/src/cli/browser-cli-actions-input/register.files-downloads.ts b/src/cli/browser-cli-actions-input/register.files-downloads.ts index 999f5d178..38c2c089d 100644 --- a/src/cli/browser-cli-actions-input/register.files-downloads.ts +++ b/src/cli/browser-cli-actions-input/register.files-downloads.ts @@ -22,6 +22,13 @@ export function registerBrowserFilesAndDownloadsCommands( browser: Command, parentOpts: (cmd: Command) => BrowserParentOpts, ) { + const resolveTimeoutAndTarget = (opts: { timeoutMs?: unknown; targetId?: unknown }) => { + const timeoutMs = Number.isFinite(opts.timeoutMs) ? Number(opts.timeoutMs) : undefined; + const targetId = + typeof opts.targetId === "string" ? opts.targetId.trim() || undefined : undefined; + return { timeoutMs, targetId }; + }; + const runDownloadCommand = async ( cmd: Command, opts: { timeoutMs?: unknown; targetId?: unknown }, @@ -29,7 +36,7 @@ export function registerBrowserFilesAndDownloadsCommands( ) => { const { parent, profile } = resolveBrowserActionContext(cmd, parentOpts); try { - const timeoutMs = Number.isFinite(opts.timeoutMs) ? Number(opts.timeoutMs) : undefined; + const { timeoutMs, targetId } = resolveTimeoutAndTarget(opts); const result = await callBrowserRequest<{ download: { path: string } }>( parent, { @@ -38,8 +45,7 @@ export function registerBrowserFilesAndDownloadsCommands( query: profile ? { profile } : undefined, body: { ...request.body, - targetId: - typeof opts.targetId === "string" ? opts.targetId.trim() || undefined : undefined, + targetId, timeoutMs, }, }, @@ -76,7 +82,7 @@ export function registerBrowserFilesAndDownloadsCommands( const { parent, profile } = resolveBrowserActionContext(cmd, parentOpts); try { const normalizedPaths = normalizeUploadPaths(paths); - const timeoutMs = Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : undefined; + const { timeoutMs, targetId } = resolveTimeoutAndTarget(opts); const result = await callBrowserRequest<{ download: { path: string } }>( parent, { @@ -88,7 +94,7 @@ export function registerBrowserFilesAndDownloadsCommands( ref: opts.ref?.trim() || undefined, inputRef: opts.inputRef?.trim() || undefined, element: opts.element?.trim() || undefined, - targetId: opts.targetId?.trim() || undefined, + targetId, timeoutMs, }, }, @@ -172,7 +178,7 @@ export function registerBrowserFilesAndDownloadsCommands( return; } try { - const timeoutMs = Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : undefined; + const { timeoutMs, targetId } = resolveTimeoutAndTarget(opts); const result = await callBrowserRequest( parent, { @@ -182,7 +188,7 @@ export function registerBrowserFilesAndDownloadsCommands( body: { accept, promptText: opts.prompt?.trim() || undefined, - targetId: opts.targetId?.trim() || undefined, + targetId, timeoutMs, }, }, diff --git a/src/cli/browser-cli-debug.ts b/src/cli/browser-cli-debug.ts index 2c4537438..a0b7004b8 100644 --- a/src/cli/browser-cli-debug.ts +++ b/src/cli/browser-cli-debug.ts @@ -12,6 +12,20 @@ function runBrowserDebug(action: () => Promise) { }); } +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 }, );