refactor(cli): share browser resize output helper

This commit is contained in:
Peter Steinberger
2026-02-15 18:25:47 +00:00
parent 7ef956d224
commit 394e69a2f8
3 changed files with 57 additions and 48 deletions

View File

@@ -1,11 +1,8 @@
import type { Command } from "commander";
import { danger } from "../../globals.js";
import { defaultRuntime } from "../../runtime.js";
import {
callBrowserRequest,
callBrowserResize,
type BrowserParentOpts,
} from "../browser-cli-shared.js";
import { runBrowserResizeWithOutput } from "../browser-cli-resize.js";
import { callBrowserRequest, type BrowserParentOpts } from "../browser-cli-shared.js";
import { requireRef, resolveBrowserActionContext } from "./shared.js";
export function registerBrowserNavigationCommands(
@@ -52,27 +49,16 @@ export function registerBrowserNavigationCommands(
.option("--target-id <id>", "CDP target id (or unique prefix)")
.action(async (width: number, height: number, opts, cmd) => {
const { parent, profile } = resolveBrowserActionContext(cmd, parentOpts);
if (!Number.isFinite(width) || !Number.isFinite(height)) {
defaultRuntime.error(danger("width and height must be numbers"));
defaultRuntime.exit(1);
return;
}
try {
const result = await callBrowserResize(
await runBrowserResizeWithOutput({
parent,
{
profile,
width,
height,
targetId: opts.targetId,
},
{ timeoutMs: 20000 },
);
if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2));
return;
}
defaultRuntime.log(`resized to ${width}x${height}`);
profile,
width,
height,
targetId: opts.targetId,
timeoutMs: 20000,
successMessage: `resized to ${width}x${height}`,
});
} catch (err) {
defaultRuntime.error(danger(String(err)));
defaultRuntime.exit(1);