Lightpanda: the headless browser designed for AI and automation
Merge remote-tracking branch 'origin/main' into tool-telemetry
Adrià Arrufat8646b1288573
diff --cc src/agent/Agent.zigindex 69b202ecc,33020bec3..91d4e0217--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@@ -2007,9 -2021,8 +2021,9 @@@ fn toolOutcome(self: *Agent, allocator.inline_image = true,.record = self.capturing_for_save,.nav_note = true,+ .source = .llm,});- selector.* = result.selector;+ saved.* = .{ .selector = result.selector, .navigated = result.navigated };const content = capToolOutput(allocator, tool_name, result.text);return .{.content = content,diff --cc src/browser/tools.zigindex 72e3cc380,7ff544485..13fe2021f--- a/src/browser/tools.zig+++ b/src/browser/tools.zig@@@ -2913,6 -2871,58 +2943,58 @@@ test "tools: a read tool navigating bytry std.testing.expect(std.mem.indexOf(u8, s.text, "rate-limit") == null);}+ test "tools: a read tool keeps a page that moved within the document" {+ var registry: NodeRegistry = .init(std.testing.allocator);+ defer registry.deinit();++ const session = testing.test_session;+ defer if (session.primaryPage()) |page| page.close();++ const aa = testing.arena_allocator;+ const url = "http://localhost:9582/src/browser/tests/mcp_actions.html";- _ = try call(aa, session, ®istry, "goto", try std.json.parseFromSliceLeaky(std.json.Value, aa, "{\"url\":\"" ++ url ++ "\"}", .{}), .{});++ _ = try call(aa, session, ®istry, "goto", try std.json.parseFromSliceLeaky(std.json.Value, aa, "{\"url\":\"" ++ url ++ "\"}", .{}), .{ .source = .user });+ _ = try call(aa, session, ®istry, "evaluate", try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"script":"document.body.dataset.mark = 'kept'; history.pushState(null, '', '?moved')"}- , .{}), .{});++ , .{}), .{ .source = .user });+- const r = try call(aa, session, ®istry, "markdown", try std.json.parseFromSliceLeaky(std.json.Value, aa, "{\"url\":\"" ++ url ++ "\"}", .{}), .{ .nav_note = true });++ const r = try call(aa, session, ®istry, "markdown", try std.json.parseFromSliceLeaky(std.json.Value, aa, "{\"url\":\"" ++ url ++ "\"}", .{}), .{ .nav_note = true, .source = .user });+ try std.testing.expect(std.mem.startsWith(u8, r.text, "The page is at " ++ url ++ "?moved, not " ++ url ++ ":"));+ try std.testing.expect(!r.navigated);++ const empty = try call(aa, session, ®istry, "tree", try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"url":""}- , .{}), .{ .nav_note = true });++ , .{}), .{ .nav_note = true, .source = .user });+ try std.testing.expect(!empty.is_error and !empty.navigated);++ const mark = try call(aa, session, ®istry, "evaluate", try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"script":"document.body.dataset.mark"}- , .{}), .{});++ , .{}), .{ .source = .user });+ try std.testing.expectEqualStrings("kept", mark.text);+ }++ test "tools: a read tool keeps a page reached through a redirect" {+ var registry: NodeRegistry = .init(std.testing.allocator);+ defer registry.deinit();++ const session = testing.test_session;+ defer if (session.primaryPage()) |page| page.close();++ const aa = testing.arena_allocator;+ const args = try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"url":"http://localhost:9582/xhr/redirect"}+ , .{});- _ = try call(aa, session, ®istry, "goto", args, .{});++ _ = try call(aa, session, ®istry, "goto", args, .{ .source = .user });+ _ = try call(aa, session, ®istry, "evaluate", try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"script":"document.body.dataset.mark = 'kept'"}- , .{}), .{});++ , .{}), .{ .source = .user });+- _ = try call(aa, session, ®istry, "markdown", args, .{});++ _ = try call(aa, session, ®istry, "markdown", args, .{ .source = .user });+ const mark = try call(aa, session, ®istry, "evaluate", try std.json.parseFromSliceLeaky(std.json.Value, aa,+ \\{"script":"document.body.dataset.mark"}- , .{}), .{});++ , .{}), .{ .source = .user });+ try std.testing.expectEqualStrings("kept", mark.text);+ }+test "tools: a bot challenge is named" {var registry: NodeRegistry = .init(std.testing.allocator);defer registry.deinit();