Files
openclaw/extensions/browser/src/cli/browser-cli-resize.ts
2026-05-29 07:51:27 +02:00

45 lines
1.2 KiB
TypeScript

import { ACT_MAX_VIEWPORT_DIMENSION } from "../browser/act-policy.js";
import { callBrowserResize, type BrowserParentOpts } from "./browser-cli-shared.js";
import { danger, defaultRuntime } from "./core-api.js";
export async function runBrowserResizeWithOutput(params: {
parent: BrowserParentOpts;
profile?: string;
width: number;
height: number;
targetId?: string;
timeoutMs?: number;
successMessage: string;
}): Promise<void> {
const { width, height } = params;
if (!Number.isFinite(width) || !Number.isFinite(height)) {
defaultRuntime.error(danger("width and height must be numbers"));
defaultRuntime.exit(1);
return;
}
if (width > ACT_MAX_VIEWPORT_DIMENSION || height > ACT_MAX_VIEWPORT_DIMENSION) {
defaultRuntime.error(
danger(`width and height must not exceed ${ACT_MAX_VIEWPORT_DIMENSION}`),
);
defaultRuntime.exit(1);
return;
}
const result = await callBrowserResize(
params.parent,
{
profile: params.profile,
width,
height,
targetId: params.targetId,
},
{ timeoutMs: params.timeoutMs ?? 20000 },
);
if (params.parent?.json) {
defaultRuntime.writeJson(result);
return;
}
defaultRuntime.log(params.successMessage);
}