From 2ddcc6d9e640f24ea2d6f401c90e092749719393 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 19 Sep 2025 14:27:53 +0800 Subject: [PATCH] Replace --noscript with more advanced --strip_mode --noscript is deprecated (warning) and automatically maps to --strip_mode js --strip_mode takes a comma separated list of values. From the help: - "js" script and link[as=script, rel=preload] - "ui" includes img, picture, video, css and svg - "css" includes style and link[rel=stylesheet] - "full" includes js, ui and css Maybe this is overkill, but i sometimes find myself looking --dump outputs over and over again, and removing noise (like HUGE svgs) seems like a small improvement. --- src/browser/dump.zig | 57 ++++++++++++++++++++++++++++++++++++++++---- src/browser/page.zig | 4 ++-- src/main.zig | 54 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 102 insertions(+), 13 deletions(-) diff --git a/src/browser/dump.zig b/src/browser/dump.zig index 11ef239a..dab2d14d 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -26,7 +26,13 @@ pub const Opts = struct { // set to include element shadowroots in the dump page: ?*const Page = null, - exclude_scripts: bool = false, + strip_mode: StripMode = .{}, + + pub const StripMode = struct { + js: bool = false, + ui: bool = false, + css: bool = false, + }; }; // writer must be a std.io.Writer @@ -67,7 +73,7 @@ pub fn writeNode(node: *parser.Node, opts: Opts, writer: *std.Io.Writer) anyerro .element => { // open the tag const tag_type = try parser.nodeHTMLGetTagType(node) orelse .undef; - if (opts.exclude_scripts and try isScriptOrRelated(tag_type, node)) { + if (try isStripped(tag_type, node, opts.strip_mode)) { return; } @@ -159,9 +165,22 @@ pub fn writeChildren(root: *parser.Node, opts: Opts, writer: *std.Io.Writer) !vo } } -// When `exclude_scripts` is passed to dump, we don't include