mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 07:01:40 +03:00
refactor(cli): share browser resize request
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
import type { Command } from "commander";
|
import type { Command } from "commander";
|
||||||
import { danger } from "../../globals.js";
|
import { danger } from "../../globals.js";
|
||||||
import { defaultRuntime } from "../../runtime.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";
|
import { requireRef, resolveBrowserActionContext } from "./shared.js";
|
||||||
|
|
||||||
export function registerBrowserNavigationCommands(
|
export function registerBrowserNavigationCommands(
|
||||||
@@ -54,18 +58,13 @@ export function registerBrowserNavigationCommands(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await callBrowserRequest(
|
const result = await callBrowserResize(
|
||||||
parent,
|
parent,
|
||||||
{
|
{
|
||||||
method: "POST",
|
profile,
|
||||||
path: "/act",
|
|
||||||
query: profile ? { profile } : undefined,
|
|
||||||
body: {
|
|
||||||
kind: "resize",
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
targetId: opts.targetId,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ timeoutMs: 20000 },
|
{ timeoutMs: 20000 },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -60,3 +60,25 @@ export async function callBrowserRequest<T>(
|
|||||||
}
|
}
|
||||||
return payload as T;
|
return payload as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function callBrowserResize(
|
||||||
|
opts: BrowserParentOpts,
|
||||||
|
params: { profile?: string; width: number; height: number; targetId?: string },
|
||||||
|
extra?: { timeoutMs?: number },
|
||||||
|
): Promise<unknown> {
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import type { Command } from "commander";
|
|||||||
import { danger } from "../globals.js";
|
import { danger } from "../globals.js";
|
||||||
import { defaultRuntime } from "../runtime.js";
|
import { defaultRuntime } from "../runtime.js";
|
||||||
import { parseBooleanValue } from "../utils/boolean.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 { registerBrowserCookiesAndStorageCommands } from "./browser-cli-state.cookies-storage.js";
|
||||||
import { runCommandWithRuntime } from "./cli-utils.js";
|
import { runCommandWithRuntime } from "./cli-utils.js";
|
||||||
|
|
||||||
@@ -41,18 +45,13 @@ export function registerBrowserStateCommands(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await runBrowserCommand(async () => {
|
await runBrowserCommand(async () => {
|
||||||
const result = await callBrowserRequest(
|
const result = await callBrowserResize(
|
||||||
parent,
|
parent,
|
||||||
{
|
{
|
||||||
method: "POST",
|
profile,
|
||||||
path: "/act",
|
|
||||||
query: profile ? { profile } : undefined,
|
|
||||||
body: {
|
|
||||||
kind: "resize",
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
targetId: opts.targetId,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ timeoutMs: 20000 },
|
{ timeoutMs: 20000 },
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user