Make CDP frame-aware

This commit is contained in:
Karl Seguin
2026-02-18 12:17:22 +08:00
parent 815319140f
commit bb01a5cb31
2 changed files with 10 additions and 8 deletions

View File

@@ -1210,7 +1210,7 @@ pub fn iframeAddedCallback(self: *Page, iframe: *Element.Html.IFrame) !void {
page_frame.iframe = iframe; page_frame.iframe = iframe;
iframe._content_window = page_frame.window; iframe._content_window = page_frame.window;
page_frame.navigate(src, .{}) catch |err| { page_frame.navigate(src, .{.reason = .initialFrameNavigation}) catch |err| {
log.warn(.page, "iframe navigate failure", .{ .url = src, .err = err }); log.warn(.page, "iframe navigate failure", .{ .url = src, .err = err });
self._pending_loads -= 1; self._pending_loads -= 1;
iframe._content_window = null; iframe._content_window = null;
@@ -3119,6 +3119,7 @@ pub const NavigateReason = enum {
script, script,
history, history,
navigation, navigation,
initialFrameNavigation,
}; };
pub const NavigateOpts = struct { pub const NavigateOpts = struct {

View File

@@ -252,13 +252,14 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
.address_bar => null, .address_bar => null,
}; };
if (reason_) |reason| { if (reason_) |reason| {
try cdp.sendEvent("Page.frameScheduledNavigation", .{ if (reason != .initialFrameNavigation) {
.frameId = frame_id, try cdp.sendEvent("Page.frameScheduledNavigation", .{
.delay = 0, .frameId = frame_id,
.reason = reason, .delay = 0,
.url = event.url, .reason = reason,
}, .{ .session_id = session_id }); .url = event.url,
}, .{ .session_id = session_id });
}
try cdp.sendEvent("Page.frameRequestedNavigation", .{ try cdp.sendEvent("Page.frameRequestedNavigation", .{
.frameId = frame_id, .frameId = frame_id,
.reason = reason, .reason = reason,