

























1+import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime";
12import { resolveBrowserNavigationProxyMode } from "../browser-proxy-mode.js";
23import {
34BrowserProfileUnavailableError,
@@ -12,13 +13,7 @@ import {
1213import type { BrowserRouteContext, ProfileContext } from "../server-context.js";
1314import { resolveTargetIdFromTabs } from "../target-id.js";
1415import type { BrowserRequest, BrowserResponse, BrowserRouteRegistrar } from "./types.js";
15-import {
16-asyncBrowserRoute,
17-getProfileContext,
18-jsonError,
19-toNumber,
20-toStringOrEmpty,
21-} from "./utils.js";
16+import { asyncBrowserRoute, getProfileContext, jsonError, toStringOrEmpty } from "./utils.js";
22172318function resolveTabsProfileContext(
2419req: BrowserRequest,
@@ -136,6 +131,27 @@ function readOptionalTabLabel(body: unknown): string | undefined {
136131return label || undefined;
137132}
138133134+function readTabIndex(
135+res: BrowserResponse,
136+body: unknown,
137+opts?: { required?: boolean },
138+): number | null | undefined {
139+const record = body && typeof body === "object" ? (body as Record<string, unknown>) : {};
140+if (!Object.hasOwn(record, "index")) {
141+if (opts?.required) {
142+jsonError(res, 400, "index is required");
143+return null;
144+}
145+return undefined;
146+}
147+const index = parseStrictNonNegativeInteger(record.index);
148+if (index === undefined) {
149+jsonError(res, 400, "index must be a non-negative integer");
150+return null;
151+}
152+return index;
153+}
154+139155async function runTabTargetMutation(params: {
140156req: BrowserRequest;
141157res: BrowserResponse;
@@ -269,7 +285,6 @@ export function registerBrowserTabRoutes(app: BrowserRouteRegistrar, ctx: Browse
269285"/tabs/action",
270286asyncBrowserRoute(async (req, res) => {
271287const action = toStringOrEmpty((req.body as { action?: unknown })?.action);
272-const index = toNumber((req.body as { index?: unknown })?.index);
273288274289await withTabsProfileRoute({
275290 req,
@@ -320,6 +335,10 @@ export function registerBrowserTabRoutes(app: BrowserRouteRegistrar, ctx: Browse
320335if (!(await ensureBrowserRunning(profileCtx, res))) {
321336return;
322337}
338+const index = readTabIndex(res, req.body);
339+if (index === null) {
340+return;
341+}
323342const tabs = await profileCtx.listTabs();
324343const target = resolveIndexedTab(tabs, index);
325344if (!target) {
@@ -330,8 +349,9 @@ export function registerBrowserTabRoutes(app: BrowserRouteRegistrar, ctx: Browse
330349}
331350332351if (action === "select") {
333-if (typeof index !== "number") {
334-return jsonError(res, 400, "index is required");
352+const index = readTabIndex(res, req.body, { required: true });
353+if (index === null || index === undefined) {
354+return;
335355}
336356if (!(await ensureBrowserRunning(profileCtx, res))) {
337357return;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。