Skip to content

Commit 1e48ca4

Browse files
committed
fix(browser): default non-finite chrome mcp click delays
1 parent 4b147f2 commit 1e48ca4

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

extensions/browser/src/browser/chrome-mcp.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from "node:os";
33
import path from "node:path";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import {
6+
clickChromeMcpCoords,
67
clickChromeMcpElement,
78
buildChromeMcpArgs,
89
decodeChromeMcpStderrTail,
@@ -509,6 +510,31 @@ describe("chrome MCP page parsing", () => {
509510
expect(result).toBe(123);
510511
});
511512

513+
it("defaults non-finite coordinate click delays before injecting the browser script", async () => {
514+
const session = createFakeSession();
515+
const callTool = vi.fn(async ({ name }: ToolCall) => {
516+
if (name === "evaluate_script") {
517+
return { content: [{ type: "text", text: "```json\nnull\n```" }] };
518+
}
519+
throw new Error(`unexpected tool ${name}`);
520+
});
521+
session.client.callTool = callTool as typeof session.client.callTool;
522+
setChromeMcpSessionFactoryForTest(async () => session);
523+
524+
await clickChromeMcpCoords({
525+
profileName: "chrome-live",
526+
targetId: "1",
527+
x: 10,
528+
y: 20,
529+
delayMs: Number.NaN,
530+
});
531+
532+
const callToolMock = callTool as unknown as ToolCallMock;
533+
const evaluateCall = callToolMock.mock.calls.find(([call]) => call.name === "evaluate_script");
534+
const fn = evaluateCall?.[0].arguments?.function;
535+
expect(typeof fn === "string" ? fn : "").toContain("const delayMs = 0;");
536+
});
537+
512538
it("does not cache an ephemeral availability probe before the next real attach", async () => {
513539
let factoryCalls = 0;
514540
const closeMocks: Array<ReturnType<typeof vi.fn>> = [];

extensions/browser/src/browser/chrome-mcp.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { setTimeout as sleepTimeout } from "node:timers/promises";
77
import { promisify } from "node:util";
88
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
99
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
10-
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
10+
import {
11+
parseStrictPositiveInteger,
12+
resolveNonNegativeIntegerOption,
13+
} from "openclaw/plugin-sdk/number-runtime";
1114
import {
1215
normalizeOptionalString,
1316
readStringValue,
@@ -1320,7 +1323,7 @@ export async function clickChromeMcpCoords(params: {
13201323
const pressedButtons = button === "middle" ? 4 : button === "right" ? 2 : 1;
13211324
const x = JSON.stringify(params.x);
13221325
const y = JSON.stringify(params.y);
1323-
const delayMs = JSON.stringify(Math.max(0, Math.floor(params.delayMs ?? 0)));
1326+
const delayMs = JSON.stringify(resolveNonNegativeIntegerOption(params.delayMs, 0));
13241327
const doubleClick = params.doubleClick ? "true" : "false";
13251328
await evaluateChromeMcpScript({
13261329
profileName: params.profileName,

0 commit comments

Comments
 (0)