From 5e1fe656e805d8f5d43031e007637cd00024f57a Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Mon, 15 Apr 2024 21:34:00 +0200 Subject: [PATCH] send Target.attachedToTarget after Target.setAutoAttach Signed-off-by: Francis Bouvier --- src/cdp/target.zig | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/cdp/target.zig b/src/cdp/target.zig index bca669cb..716e190f 100644 --- a/src/cdp/target.zig +++ b/src/cdp/target.zig @@ -5,6 +5,7 @@ const Ctx = server.CmdContext; const SendFn = server.SendFn; const result = @import("cdp.zig").result; const getParams = @import("cdp.zig").getParams; +const stringify = @import("cdp.zig").stringify; const TargetMethods = enum { setAutoAttach, @@ -27,11 +28,15 @@ pub fn target( }; } +const SessionID = "9559320D92474062597D9875C664CAC0"; +const TargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; +const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9"; + fn tagetSetAutoAttach( alloc: std.mem.Allocator, id: u64, scanner: *std.json.Scanner, - _: *Ctx, + ctx: *Ctx, ) ![]const u8 { const Params = struct { autoAttach: bool, @@ -40,11 +45,29 @@ fn tagetSetAutoAttach( }; const params = try getParams(alloc, Params, scanner); std.log.debug("params {any}", .{params}); + + const AttachToTarget = struct { + method: []const u8 = "Target.attachedToTarget", + params: struct { + sessionId: []const u8 = SessionID, + targetInfo: struct { + targetId: []const u8 = TargetID, + type: []const u8 = "page", + title: []const u8 = "New Incognito tab", + url: []const u8 = "chrome://newtab/", + attached: bool = true, + canAccessOpener: bool = false, + browserContextId: []const u8 = BrowserContextID, + } = .{}, + waitingForDebugger: bool = false, + } = .{}, + }; + const attached = try stringify(alloc, AttachToTarget{}); + try server.sendLater(ctx, attached, 0); + return result(alloc, id, null, null); } -const TargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; - fn tagetGetTargetInfo( alloc: std.mem.Allocator, id: u64,