Merge pull request #2426 from lightpanda-io/feat/cdp-disable-iframes

Feat/cdp disable iframes
This commit is contained in:
Karl Seguin authored and GitHub committed 2026-05-12 13:16:16 +08:00
commit e9b2aa4946
4 files changed
+41

No files matched your search

+19
View File
@@ -98,6 +98,7 @@ const CommonOptions = .{
.{ .name = "cookie_jar", .type = ?[]const u8 },
.{ .name = "storage_engine", .type = ?Storage.EngineType },
.{ .name = "storage_sqlite_path", .type = ?[:0]const u8 },
.{ .name = "disable_subframes", .type = bool },
};
fn dumpValidator(_: Allocator, args: *std.process.ArgIterator) !?DumpFormat {
@@ -239,6 +240,13 @@ pub fn obeyRobots(self: *const Config) bool {
};
}
pub fn disableSubframes(self: *const Config) bool {
return switch (self.mode) {
inline .serve, .fetch, .mcp => |opts| opts.disable_subframes,
else => unreachable,
};
}
pub fn httpProxy(self: *const Config) ?[:0]const u8 {
return switch (self.mode) {
inline .serve, .fetch, .mcp => |opts| opts.http_proxy,
@@ -526,6 +534,17 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void {
\\ we make requests towards.
\\ Defaults to false.
\\
\\--disable-subframes
\\ Skip loading <iframe> elements. The HTML parser registers them
\\ in the DOM but no child frame, document fetch, or
\\ Page.frameAttached / Runtime.executionContextCreated events are
\\ produced. Useful for pages that load many analytics / pixel
\\ iframes where each subframe navigation invalidates driver-side
\\ executionContextIds (lightpanda-io/browser#2400). On the CDP
\\ serve path, drivers can also toggle this per-session via the
\\ LP.configureLoading method.
\\ Defaults to false.
\\
\\--block-private-networks
\\ Blocks HTTP requests to private/internal IP addresses
\\ after DNS resolution. Useful for sandboxing, multi-tenant
+5
View File
@@ -1303,6 +1303,11 @@ pub fn iframeAddedCallback(self: *Frame, iframe: *IFrame) !void {
if (iframe._executed) {
return;
}
if (!self._session.subframe_loading_enabled) {
// configured not to load frames
iframe._executed = true;
return;
}
var src = iframe.asElement().getAttributeSafe(comptime .wrap("src")) orelse "";
if (src.len == 0) {
+5
View File
@@ -78,6 +78,9 @@ _pending: ?*Page = null,
frame_id_gen: u32 = 0,
loader_id_gen: u32 = 0,
// configuration (or CDP command) to disable iframe loading
subframe_loading_enabled: bool = true,
pub fn init(self: *Session, browser: *Browser, notification: *Notification) !void {
const allocator = browser.app.allocator;
const arena_pool = browser.arena_pool;
@@ -96,6 +99,8 @@ pub fn init(self: *Session, browser: *Browser, notification: *Notification) !voi
.notification = notification,
.fc_identity_pool = .init(allocator),
.cookie_jar = storage.Cookie.Jar.init(allocator),
// CLI default; LP.configureLoading can flip this per-session.
.subframe_loading_enabled = !browser.app.config.disableSubframes(),
};
}
+12
View File
@@ -42,6 +42,7 @@ pub fn processMessage(cmd: *CDP.Command) !void {
scrollNode,
waitForSelector,
handleJavaScriptDialog,
configureLoading,
}, cmd.input.action) orelse return error.UnknownMethod;
switch (action) {
@@ -56,9 +57,20 @@ pub fn processMessage(cmd: *CDP.Command) !void {
.scrollNode => return scrollNode(cmd),
.waitForSelector => return waitForSelector(cmd),
.handleJavaScriptDialog => return handleJavaScriptDialog(cmd),
.configureLoading => return configureLoading(cmd),
}
}
fn configureLoading(cmd: *CDP.Command) !void {
const params = (try cmd.params(struct {
subFrame: bool = true,
})) orelse return error.InvalidParams;
const bc = cmd.browser_context orelse return error.NoBrowserContext;
bc.session.subframe_loading_enabled = params.subFrame;
return cmd.sendResult(null, .{});
}
fn getSemanticTree(cmd: anytype) !void {
const Params = struct {
format: ?enum { text } = null,