diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 2d2ae708..2f78a23d 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -190,3 +190,5 @@ pub fn getSessionID(scanner: *std.json.Scanner) !?[]const u8 { // ------ pub const SessionID = "9559320D92474062597D9875C664CAC0"; +pub const URLBase = "chrome://newtab/"; +pub const FrameID = "90D14BBD8AED408A0467AC93100BCDBE"; diff --git a/src/cdp/page.zig b/src/cdp/page.zig index a26fbe8a..e71cce21 100644 --- a/src/cdp/page.zig +++ b/src/cdp/page.zig @@ -41,9 +41,7 @@ fn enable( return result(alloc, id, null, null, sessionID); } -const FrameTreeID = "90D14BBD8AED408A0467AC93100BCDBE"; const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C"; -const URLBase = "chrome://newtab/"; fn getFrameTree( alloc: std.mem.Allocator, @@ -55,11 +53,11 @@ fn getFrameTree( const FrameTree = struct { frameTree: struct { frame: struct { - id: []const u8 = FrameTreeID, + id: []const u8 = cdp.FrameID, loaderId: []const u8 = LoaderID, - url: []const u8 = URLBase, + url: []const u8 = cdp.URLBase, domainAndRegistry: []const u8 = "", - securityOrigin: []const u8 = URLBase, + securityOrigin: []const u8 = cdp.URLBase, mimeType: []const u8 = "mimeType", adFrameStatus: struct { adFrameType: []const u8 = "none", diff --git a/src/cdp/target.zig b/src/cdp/target.zig index 9b330025..79f2b5bf 100644 --- a/src/cdp/target.zig +++ b/src/cdp/target.zig @@ -9,7 +9,7 @@ const stringify = cdp.stringify; const TargetMethods = enum { setAutoAttach, - // getTargetInfo, + getTargetInfo, }; pub fn target( @@ -23,12 +23,12 @@ pub fn target( return error.UnknownMethod; return switch (method) { .setAutoAttach => tagetSetAutoAttach(alloc, id, scanner, ctx), - // .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner, ctx), + .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner, ctx), }; } -const SessionID = "9559320D92474062597D9875C664CAC0"; -const TargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; +const PageTargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; +const BrowserTargetID = "2d2bdef9-1c95-416f-8c0e-83f3ab73a30c"; const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9"; const TargetFilter = struct { @@ -51,26 +51,28 @@ 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, + const sessionID = try cdp.getSessionID(scanner); + + if (sessionID == null) { + const AttachToTarget = struct { + sessionId: []const u8 = cdp.SessionID, targetInfo: struct { - targetId: []const u8 = TargetID, + targetId: []const u8 = PageTargetID, type: []const u8 = "page", title: []const u8 = "New Incognito tab", - url: []const u8 = "chrome://newtab/", + url: []const u8 = cdp.URLBase, attached: bool = true, canAccessOpener: bool = false, browserContextId: []const u8 = BrowserContextID, } = .{}, waitingForDebugger: bool = false, - } = .{}, - }; - const attached = try stringify(alloc, AttachToTarget{}); - try server.sendSync(ctx, attached); + }; + const attached = try cdp.method(alloc, "Target.attachedToTarget", AttachToTarget, .{}, null); + std.log.debug("res {s}", .{attached}); + try server.sendSync(ctx, attached); + } - return result(alloc, id, null, null, null); + return result(alloc, id, null, null, sessionID); } fn tagetGetTargetInfo( @@ -79,22 +81,29 @@ fn tagetGetTargetInfo( scanner: *std.json.Scanner, _: *Ctx, ) ![]const u8 { - _ = scanner; + // input + const Params = struct { + targetId: ?[]const u8 = null, + }; + _ = try getParams(alloc, Params, scanner); + + // output const TargetInfo = struct { targetId: []const u8, type: []const u8, - title: []const u8, - url: []const u8, - attached: bool, - canAccessOpener: bool, - + title: []const u8 = "", + url: []const u8 = "", + attached: bool = true, + openerId: ?[]const u8 = null, + canAccessOpener: bool = false, + openerFrameId: ?[]const u8 = null, browserContextId: ?[]const u8 = null, + subtype: ?[]const u8 = null, }; const targetInfo = TargetInfo{ - .targetId = TargetID, - .type = "page", + .targetId = BrowserTargetID, + .type = "browser", }; - _ = targetInfo; - return result(alloc, id, null, null); + return result(alloc, id, TargetInfo, targetInfo, null); }