Merge pull request #2527 from lightpanda-io/waitforselector-notfound

tools: map waitForSelector timeout to NodeNotFound
This commit is contained in:
Adrià Arrufat
2026-05-22 19:13:17 +02:00
committed by GitHub
2 changed files with 12 additions and 5 deletions

View File

@@ -961,9 +961,15 @@ fn execWaitForSelector(arena: std.mem.Allocator, session: *lp.Session, registry:
const timeout_ms = args.timeout orelse 5000;
const node = lp.actions.waitForSelector(args.selector, timeout_ms, session) catch |err| {
if (err == error.InvalidSelector) return ToolError.InvalidParams;
return ToolError.InternalError;
const node = lp.actions.waitForSelector(args.selector, timeout_ms, session) catch |err| switch (err) {
error.InvalidSelector => return ToolError.InvalidParams,
// Timeout w/o a match: same outcome as `/hover selector=…` on a missing
// node — surface `NodeNotFound` so the LLM sees a consistent signal.
error.Timeout => return ToolError.NodeNotFound,
else => {
log.debug(.browser, "waitForSelector error", .{ .err = @errorName(err) });
return ToolError.InternalError;
},
};
const registered = registry.register(node) catch return ToolError.InternalError;

View File

@@ -886,14 +886,15 @@ test "MCP - waitForSelector: timeout" {
);
defer server.deinit();
// waitForSelector with a short timeout on a non-existent element should error
// Missing element after the timeout surfaces as NodeNotFound, matching
// the error /hover, /click, etc. produce when their selector misses.
const msg =
\\{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"waitForSelector","arguments":{"selector":"#nonexistent","timeout":100}}}
;
try router.handleMessage(server, testing.arena_allocator, msg);
try testing.expectJson(.{
.id = 1,
.@"error" = struct {}{},
.@"error" = .{ .message = "NodeNotFound" },
}, out.written());
}