From a7c3bad9ad385bd913bb88850b41b2b0ba56c8b6 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Oct 2025 17:45:19 +0200 Subject: [PATCH] cdp: implement url parameter on createTarget --- src/browser/page.zig | 14 +++++++++++++- src/cdp/domains/target.zig | 13 +++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/browser/page.zig b/src/browser/page.zig index 833c683f..5bfd6374 100644 --- a/src/browser/page.zig +++ b/src/browser/page.zig @@ -556,7 +556,19 @@ pub const Page = struct { // We do not processHTMLDoc here as we know we don't have any scripts // This assumption may be false when CDP Page.addScriptToEvaluateOnNewDocument is implemented - try HTMLDocument.documentIsComplete(self.window.document, self); + self.documentIsComplete(); + + self.session.browser.notification.dispatch(.page_navigate, &.{ + .opts = opts, + .url = request_url, + .timestamp = timestamp(), + }); + + self.session.browser.notification.dispatch(.page_navigated, &.{ + .url = request_url, + .timestamp = timestamp(), + }); + return; } diff --git a/src/cdp/domains/target.zig b/src/cdp/domains/target.zig index 26f4cfbe..e58f278d 100644 --- a/src/cdp/domains/target.zig +++ b/src/cdp/domains/target.zig @@ -109,7 +109,7 @@ fn disposeBrowserContext(cmd: anytype) !void { fn createTarget(cmd: anytype) !void { const params = (try cmd.params(struct { - // url: []const u8, + url: []const u8 = "about:blank", // width: ?u64 = null, // height: ?u64 = null, browserContextId: ?[]const u8 = null, @@ -167,7 +167,7 @@ fn createTarget(cmd: anytype) !void { .targetInfo = TargetInfo{ .attached = false, .targetId = target_id, - .title = "about:blank", + .title = params.url, .browserContextId = bc.id, .url = "about:blank", }, @@ -178,6 +178,11 @@ fn createTarget(cmd: anytype) !void { try doAttachtoTarget(cmd, target_id); } + try page.navigate(params.url, .{ + .reason = .address_bar, + .cdp_id = cmd.input.id, + }); + try cmd.sendResult(.{ .targetId = target_id, }, .{}); @@ -517,7 +522,7 @@ test "cdp.target: createTarget" { { var ctx = testing.context(); defer ctx.deinit(); - try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .url = "about/blank" } }); + try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .url = "about:blank" } }); // should create a browser context const bc = ctx.cdp().browser_context.?; @@ -529,7 +534,7 @@ test "cdp.target: createTarget" { defer ctx.deinit(); // active auto attach to get the Target.attachedToTarget event. try ctx.processMessage(.{ .id = 9, .method = "Target.setAutoAttach", .params = .{ .autoAttach = true, .waitForDebuggerOnStart = false } }); - try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .url = "about/blank" } }); + try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .url = "about:blank" } }); // should create a browser context const bc = ctx.cdp().browser_context.?;