@@ -43,8 +43,9 @@ import {
|
43 | 43 | shouldUsePlaywrightForScreenshot, |
44 | 44 | } from "./agent.snapshot.plan.js"; |
45 | 45 | import { EXISTING_SESSION_LIMITS } from "./existing-session-limits.js"; |
| 46 | +import { readRoutePositiveInteger } from "./route-numeric.js"; |
46 | 47 | import type { BrowserResponse, BrowserRouteRegistrar } from "./types.js"; |
47 | | -import { asyncBrowserRoute, jsonError, toBoolean, toNumber, toStringOrEmpty } from "./utils.js"; |
| 48 | +import { asyncBrowserRoute, jsonError, toBoolean, toStringOrEmpty } from "./utils.js"; |
48 | 49 | |
49 | 50 | const CHROME_MCP_OVERLAY_ATTR = "data-openclaw-mcp-overlay"; |
50 | 51 | |
@@ -368,11 +369,16 @@ export function registerBrowserAgentSnapshotRoutes(
|
368 | 369 | const element = toStringOrEmpty(body.element) || undefined; |
369 | 370 | const labels = toBoolean(body.labels) ?? false; |
370 | 371 | const type = body.type === "jpeg" ? "jpeg" : "png"; |
371 | | -const timeoutMsRaw = toNumber(body.timeoutMs); |
372 | | -const timeoutMs = |
373 | | -timeoutMsRaw !== undefined |
374 | | - ? normalizeBrowserTimerDelayMs(timeoutMsRaw) |
375 | | - : DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS; |
| 372 | +let timeoutMs: number; |
| 373 | +try { |
| 374 | +const timeoutMsRaw = readRoutePositiveInteger(body.timeoutMs, "timeoutMs"); |
| 375 | +timeoutMs = |
| 376 | +timeoutMsRaw !== undefined |
| 377 | + ? normalizeBrowserTimerDelayMs(timeoutMsRaw) |
| 378 | + : DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS; |
| 379 | +} catch (err) { |
| 380 | +return jsonError(res, 400, String(err instanceof Error ? err.message : err)); |
| 381 | +} |
376 | 382 | |
377 | 383 | if (fullPage && (ref || element)) { |
378 | 384 | return jsonError(res, 400, "fullPage is not supported for element screenshots"); |
|