Add a --with_frames argument to fetch

When set (defaults to not set/false), --dump will include iframe contents.

I was hoping I could add a mode to strip_mode to this, but since dump is used
extensively (e.g. innerHTML), this is something that has to be off by default
(for correctness).
This commit is contained in:
Karl Seguin
2026-02-25 15:27:44 +08:00
parent 8f179becf7
commit a818560344
6 changed files with 50 additions and 16 deletions

View File

@@ -191,7 +191,8 @@ pub const Fetch = struct {
url: [:0]const u8,
dump_mode: ?DumpFormat = null,
common: Common = .{},
withbase: bool = false,
with_base: bool = false,
with_frames: bool = false,
strip: dump.Opts.Strip = .{},
};
@@ -342,6 +343,8 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void {
\\
\\--with_base Add a <base> tag in dump. Defaults to false.
\\
\\--with_frames Includes the contents of iframes. Defaults to false.
\\
++ common_options ++
\\
\\serve command
@@ -440,6 +443,10 @@ fn inferMode(opt: []const u8) ?RunMode {
return .fetch;
}
if (std.mem.eql(u8, opt, "--with_frames")) {
return .fetch;
}
if (std.mem.eql(u8, opt, "--host")) {
return .serve;
}
@@ -539,7 +546,8 @@ fn parseFetchArgs(
args: *std.process.ArgIterator,
) !Fetch {
var dump_mode: ?DumpFormat = null;
var withbase: bool = false;
var with_base: bool = false;
var with_frames: bool = false;
var url: ?[:0]const u8 = null;
var common: Common = .{};
var strip: dump.Opts.Strip = .{};
@@ -570,7 +578,12 @@ fn parseFetchArgs(
}
if (std.mem.eql(u8, "--with_base", opt)) {
withbase = true;
with_base = true;
continue;
}
if (std.mem.eql(u8, "--with_frames", opt)) {
with_frames = true;
continue;
}
@@ -626,7 +639,8 @@ fn parseFetchArgs(
.dump_mode = dump_mode,
.strip = strip,
.common = common,
.withbase = withbase,
.with_base = with_base,
.with_frames = with_frames,
};
}