feat(cdp): implement Network.setBlockedURLs via urlPatterns

Reimplement request blocking on the non-deprecated urlPatterns shape:
each pattern carries an explicit block/allow flag (first match wins),
UrlBlocklist owns the compiled patterns plus their block flags, and the
legacy setBlockedUrls path stays for back-compat. Tests updated.
This commit is contained in:
Matt Van Horn authored and Pierre Tachoire committed 2026-07-23 12:15:49 +02:00
1 parent 311ab3aaae
commit dee40075a0
3 files changed
+40 -7

No files matched your search

+11
View File
@@ -36,6 +36,7 @@ const Network = @import("Network.zig");
const Cache = @import("cache/Cache.zig");
const RobotsGate = @import("RobotsGate.zig");
const UrlBlocklist = @import("UrlBlocklist.zig");
pub const BlockPattern = UrlBlocklist.Pattern;
const log = lp.log;
const Allocator = std.mem.Allocator;
@@ -366,6 +367,16 @@ pub fn setBlockedUrls(self: *Client, patterns: []const []const u8) !void {
self.url_blocklist = replacement;
}
pub fn setBlockedUrlPatterns(self: *Client, patterns: []const BlockPattern) !void {
const replacement: ?UrlBlocklist = if (patterns.len == 0)
null
else
try UrlBlocklist.initPatterns(self.allocator, patterns);
self.clearUrlBlocklist();
self.url_blocklist = replacement;
}
fn clearUrlBlocklist(self: *Client) void {
if (self.url_blocklist) |*blocklist| {
blocklist.deinit();