Merge pull request #1958 from lightpanda-io/runner

Extract Session.wait into a Runner
This commit is contained in:
Karl Seguin
2026-03-24 07:28:18 +08:00
committed by GitHub
16 changed files with 434 additions and 393 deletions

View File

@@ -130,9 +130,10 @@ pub fn CDPT(comptime TypeProvider: type) type {
// A bit hacky right now. The main server loop doesn't unblock for
// scheduled task. So we run this directly in order to process any
// timeouts (or http events) which are ready to be processed.
pub fn pageWait(self: *Self, ms: u32) Session.WaitResult {
const session = &(self.browser.session orelse return .no_page);
return session.wait(.{ .timeout_ms = ms });
pub fn pageWait(self: *Self, ms: u32) !Session.Runner.CDPWaitResult {
const session = &(self.browser.session orelse return error.NoPage);
var runner = try session.runner(.{});
return runner.waitCDP(.{ .ms = ms });
}
// Called from above, in processMessage which handles client messages

View File

@@ -241,12 +241,12 @@ fn waitForSelector(cmd: anytype) !void {
const params = (try cmd.params(Params)) orelse return error.InvalidParam;
const bc = cmd.browser_context orelse return error.NoBrowserContext;
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
_ = bc.session.currentPage() orelse return error.PageNotLoaded;
const timeout_ms = params.timeout orelse 5000;
const selector_z = try cmd.arena.dupeZ(u8, params.selector);
const node = lp.actions.waitForSelector(selector_z, timeout_ms, page) catch |err| {
const node = lp.actions.waitForSelector(selector_z, timeout_ms, bc.session) catch |err| {
if (err == error.InvalidSelector) return error.InvalidParam;
if (err == error.Timeout) return error.InternalError;
return error.InternalError;
@@ -316,7 +316,8 @@ test "cdp.lp: action tools" {
const page = try bc.session.createPage();
const url = "http://localhost:9582/src/browser/tests/mcp_actions.html";
try page.navigate(url, .{ .reason = .address_bar, .kind = .{ .push = null } });
_ = bc.session.wait(.{});
var runner = try bc.session.runner(.{});
try runner.wait(.{ .ms = 2000 });
// Test Click
const btn = page.document.getElementById("btn", page).?.asNode();
@@ -376,7 +377,8 @@ test "cdp.lp: waitForSelector" {
const page = try bc.session.createPage();
const url = "http://localhost:9582/src/browser/tests/mcp_wait_for_selector.html";
try page.navigate(url, .{ .reason = .address_bar, .kind = .{ .push = null } });
_ = bc.session.wait(.{});
var runner = try bc.session.runner(.{});
try runner.wait(.{ .ms = 2000 });
// 1. Existing element
try ctx.processMessage(.{

View File

@@ -136,7 +136,8 @@ const TestContext = struct {
0,
);
try page.navigate(full_url, .{});
_ = bc.session.wait(.{});
var runner = try bc.session.runner(.{});
try runner.wait(.{ .ms = 2000 });
}
return bc;
}