Skip to content

Lightpanda: the headless browser designed for AI and automation

agent: keep the wait commands literal

Adrià Arrufatbac66bc8d644
diff --git a/src/script/Recorder.zig b/src/script/Recorder.zig
index a2eacdef7..846c4899b 100644
--- a/src/script/Recorder.zig
+++ b/src/script/Recorder.zig
@@ -292,7 +292,7 @@ test "record downgrades goto before waitForSelector to domcontentloaded" {
defer recorder.deinit();
try recorder.record(parseLine(aa, "/goto https://example.com"));
- try recorder.record(parseLine(aa, "/waitForSelector selector=.story"));
+ try recorder.record(parseLine(aa, "/waitForSelector .story"));
try std.testing.expectEqualStrings(
"const page = new Page();\nawait page.goto({ url: \"https://example.com\", waitUntil: \"domcontentloaded\" });\npage.waitForSelector(\".story\");\n",
@@ -326,7 +326,7 @@ test "record preserves an explicit waitUntil on goto" {
defer recorder.deinit();
try recorder.record(parseLine(aa, "/goto https://example.com waitUntil=networkidle"));
- try recorder.record(parseLine(aa, "/waitForSelector selector=.story"));
+ try recorder.record(parseLine(aa, "/waitForSelector .story"));
try std.testing.expectEqualStrings(
"const page = new Page();\nawait page.goto({ url: \"https://example.com\", waitUntil: \"networkidle\" });\npage.waitForSelector(\".story\");\n",
diff --git a/src/script/Schema.zig b/src/script/Schema.zig
index ee774e627..26dbe90b8 100644
--- a/src/script/Schema.zig
+++ b/src/script/Schema.zig
@@ -123,8 +123,11 @@ pub fn positionalFor(tool: BrowserTool) []const []const u8 {
/// mistaken for a selector.
pub fn takesPrompt(tool: BrowserTool) bool {
return switch (tool) {
- .click, .fill, .hover, .selectOption, .setChecked, .waitForSelector, .extract, .evaluate, .waitForScript => true,
- .goto, .search, .markdown, .html, .screenshot, .links, .tree, .nodeDetails, .interactiveElements, .structuredData, .detectForms, .scroll, .waitForState, .press, .findElement, .consoleLogs, .getUrl, .getCookies, .getEnv => false,
+ .click, .fill, .hover, .selectOption, .setChecked, .extract, .evaluate => true,
+ // A wait targets what is not on the page yet, so the model has nothing
+ // to work from.
+ .waitForSelector, .waitForScript, .waitForState => false,
+ .goto, .search, .markdown, .html, .screenshot, .links, .tree, .nodeDetails, .interactiveElements, .structuredData, .detectForms, .scroll, .press, .findElement, .consoleLogs, .getUrl, .getCookies, .getEnv => false,
};
}
diff --git a/src/script/command.zig b/src/script/command.zig
index 700c0fe74..a180c5afd 100644
--- a/src/script/command.zig
+++ b/src/script/command.zig
@@ -431,6 +431,7 @@ test "parse: tools without a prompt form keep their positional" {
const aa = arena.allocator();
try testing.expectString("Enter", (try Command.parse(aa, "/press Enter")).tool_call.args.?.object.get("key").?.string);
try testing.expectString("networkidle", (try Command.parse(aa, "/waitForState networkidle")).tool_call.args.?.object.get("state").?.string);
+ try testing.expectString("#logout", (try Command.parse(aa, "/waitForSelector '#logout'")).tool_call.args.?.object.get("selector").?.string);
}
test "parse: /getEnv positional binds to optional name" {