From 457e5308a9cdca0e80a88306d47b2bbb56920720 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 05:08:02 +0000 Subject: [PATCH] refactor(cli): share browser resize request --- .../register.navigation.ts | 21 +++++++++--------- src/cli/browser-cli-shared.ts | 22 +++++++++++++++++++ src/cli/browser-cli-state.ts | 21 +++++++++--------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/cli/browser-cli-actions-input/register.navigation.ts b/src/cli/browser-cli-actions-input/register.navigation.ts index 5ab7247c32..ca632dbd52 100644 --- a/src/cli/browser-cli-actions-input/register.navigation.ts +++ b/src/cli/browser-cli-actions-input/register.navigation.ts @@ -1,7 +1,11 @@ import type { Command } from "commander"; import { danger } from "../../globals.js"; import { defaultRuntime } from "../../runtime.js"; -import { callBrowserRequest, type BrowserParentOpts } from "../browser-cli-shared.js"; +import { + callBrowserRequest, + callBrowserResize, + type BrowserParentOpts, +} from "../browser-cli-shared.js"; import { requireRef, resolveBrowserActionContext } from "./shared.js"; export function registerBrowserNavigationCommands( @@ -54,18 +58,13 @@ export function registerBrowserNavigationCommands( return; } try { - const result = await callBrowserRequest( + const result = await callBrowserResize( parent, { - method: "POST", - path: "/act", - query: profile ? { profile } : undefined, - body: { - kind: "resize", - width, - height, - targetId: opts.targetId?.trim() || undefined, - }, + profile, + width, + height, + targetId: opts.targetId, }, { timeoutMs: 20000 }, ); diff --git a/src/cli/browser-cli-shared.ts b/src/cli/browser-cli-shared.ts index 34a7bc9b95..2f2e1436a9 100644 --- a/src/cli/browser-cli-shared.ts +++ b/src/cli/browser-cli-shared.ts @@ -60,3 +60,25 @@ export async function callBrowserRequest( } return payload as T; } + +export async function callBrowserResize( + opts: BrowserParentOpts, + params: { profile?: string; width: number; height: number; targetId?: string }, + extra?: { timeoutMs?: number }, +): Promise { + return callBrowserRequest( + opts, + { + method: "POST", + path: "/act", + query: params.profile ? { profile: params.profile } : undefined, + body: { + kind: "resize", + width: params.width, + height: params.height, + targetId: params.targetId?.trim() || undefined, + }, + }, + extra, + ); +} diff --git a/src/cli/browser-cli-state.ts b/src/cli/browser-cli-state.ts index b9cbccdc7a..e2e19503ac 100644 --- a/src/cli/browser-cli-state.ts +++ b/src/cli/browser-cli-state.ts @@ -2,7 +2,11 @@ import type { Command } from "commander"; import { danger } from "../globals.js"; import { defaultRuntime } from "../runtime.js"; import { parseBooleanValue } from "../utils/boolean.js"; -import { callBrowserRequest, type BrowserParentOpts } from "./browser-cli-shared.js"; +import { + callBrowserRequest, + callBrowserResize, + type BrowserParentOpts, +} from "./browser-cli-shared.js"; import { registerBrowserCookiesAndStorageCommands } from "./browser-cli-state.cookies-storage.js"; import { runCommandWithRuntime } from "./cli-utils.js"; @@ -41,18 +45,13 @@ export function registerBrowserStateCommands( return; } await runBrowserCommand(async () => { - const result = await callBrowserRequest( + const result = await callBrowserResize( parent, { - method: "POST", - path: "/act", - query: profile ? { profile } : undefined, - body: { - kind: "resize", - width, - height, - targetId: opts.targetId?.trim() || undefined, - }, + profile, + width, + height, + targetId: opts.targetId, }, { timeoutMs: 20000 }, );