This commit is contained in:
Adrià Arrufat
2026-03-23 13:52:28 +09:00
parent c9bc370d6a
commit 4f1b499d0f
2 changed files with 4 additions and 4 deletions

View File

@@ -108,7 +108,7 @@ pub fn scroll(node: ?*DOMNode, x: ?i32, y: ?i32, page: *Page) !void {
pub fn waitForSelector(selector: [:0]const u8, timeout_ms: u32, session: *Session) !*DOMNode {
var timer = try std.time.Timer.start();
var runner = try session.runner(.{});
try runner.wait(.{.ms = timeout_ms, .until = .load});
try runner.wait(.{ .ms = timeout_ms, .until = .load });
while (true) {
const page = runner.page;
@@ -124,14 +124,14 @@ pub fn waitForSelector(selector: [:0]const u8, timeout_ms: u32, session: *Sessio
if (elapsed >= timeout_ms) {
return error.Timeout;
}
switch (try runner.tick(.{.ms = timeout_ms - elapsed})) {
switch (try runner.tick(.{ .ms = timeout_ms - elapsed })) {
.done => return error.Timeout,
.ok => |recommended_sleep_ms| {
if (recommended_sleep_ms > 0) {
// guanrateed to be <= 20ms
std.Thread.sleep(std.time.ns_per_ms * recommended_sleep_ms);
}
}
},
}
}
}

View File

@@ -378,7 +378,7 @@ test "cdp.lp: waitForSelector" {
const url = "http://localhost:9582/src/browser/tests/mcp_wait_for_selector.html";
try page.navigate(url, .{ .reason = .address_bar, .kind = .{ .push = null } });
var runner = try bc.session.runner(.{});
try runner.wait(.{.ms = 2000});
try runner.wait(.{ .ms = 2000 });
// 1. Existing element
try ctx.processMessage(.{