feat: fetch add wait_until parameter for page loads options

Add `--wait_until` and `--wait_ms` CLI arguments to configure session wait behavior. Updates `Session.wait` to evaluate specific page load states (`load`, `domcontentloaded`, `networkidle`, `fixed`) before completing the wait loop.
This commit is contained in:
shaewe180
2026-03-18 15:02:00 +08:00
parent bd2406f803
commit 09327c3897
10 changed files with 85 additions and 37 deletions

View File

@@ -217,6 +217,15 @@ pub const DumpFormat = enum {
semantic_tree_text,
};
pub const WaitUntil = enum {
load,
domcontentloaded,
networkidle,
fixed,
pub const js_enum_from_string = true;
};
pub const Fetch = struct {
url: [:0]const u8,
dump_mode: ?DumpFormat = null,
@@ -224,6 +233,8 @@ pub const Fetch = struct {
with_base: bool = false,
with_frames: bool = false,
strip: dump.Opts.Strip = .{},
wait_ms: u32 = 5000,
wait_until: WaitUntil = .load,
};
pub const Common = struct {
@@ -619,8 +630,34 @@ fn parseFetchArgs(
var url: ?[:0]const u8 = null;
var common: Common = .{};
var strip: dump.Opts.Strip = .{};
var wait_ms: u32 = 5000;
var wait_until: WaitUntil = .load;
while (args.next()) |opt| {
if (std.mem.eql(u8, "--wait_ms", opt)) {
const str = args.next() orelse {
log.fatal(.app, "missing argument value", .{ .arg = "--wait_ms" });
return error.InvalidArgument;
};
wait_ms = std.fmt.parseInt(u32, str, 10) catch |err| {
log.fatal(.app, "invalid argument value", .{ .arg = "--wait_ms", .err = err });
return error.InvalidArgument;
};
continue;
}
if (std.mem.eql(u8, "--wait_until", opt)) {
const str = args.next() orelse {
log.fatal(.app, "missing argument value", .{ .arg = "--wait_until" });
return error.InvalidArgument;
};
wait_until = std.meta.stringToEnum(WaitUntil, str) orelse {
log.fatal(.app, "invalid argument value", .{ .arg = "--wait_until", .val = str });
return error.InvalidArgument;
};
continue;
}
if (std.mem.eql(u8, "--dump", opt)) {
var peek_args = args.*;
if (peek_args.next()) |next_arg| {
@@ -709,6 +746,8 @@ fn parseFetchArgs(
.common = common,
.with_base = with_base,
.with_frames = with_frames,
.wait_ms = wait_ms,
.wait_until = wait_until,
};
}