diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index c186765e..5c056763 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -121,6 +121,7 @@ pub fn dispatch( pub const State = struct { executionContextId: u32 = 0, contextID: ?[]const u8 = null, + sessionID: ?[]const u8 = null, frameID: []const u8 = FrameID, url: []const u8 = URLBase, securityOrigin: []const u8 = URLBase, diff --git a/src/cdp/runtime.zig b/src/cdp/runtime.zig index 2cda8e74..ffdbb438 100644 --- a/src/cdp/runtime.zig +++ b/src/cdp/runtime.zig @@ -129,13 +129,11 @@ fn sendInspector( } } - ctx.sendInspector(msg.json); - if (method == .enable) { try executionContextCreated( alloc, ctx, - 0, + 1, "://", "", // TODO: hard coded ID @@ -147,10 +145,12 @@ fn sendInspector( .frameId = cdp.FrameID, }, // TODO: hard coded ID - target.BrowserContextID, + msg.sessionId orelse target.BrowserContextID, ); } + ctx.sendInspector(msg.json); + if (msg.id == null) return ""; return result(alloc, msg.id.?, null, null, msg.sessionId); diff --git a/src/cdp/target.zig b/src/cdp/target.zig index 4a367cac..6d3c611b 100644 --- a/src/cdp/target.zig +++ b/src/cdp/target.zig @@ -138,7 +138,7 @@ fn setAutoAttach( .sessionId = cdp.BrowserSessionID, .targetInfo = .{ .targetId = PageTargetID, - .title = "New Incognito tab", + .title = "about:blank", .url = cdp.URLBase, .browserContextId = BrowserContextID, }, @@ -171,8 +171,8 @@ fn attachToTarget( const attached = AttachToTarget{ .sessionId = cdp.BrowserSessionID, .targetInfo = .{ - .targetId = PageTargetID, - .title = "New Incognito tab", + .targetId = input.params.targetId, + .title = "about:blank", .url = cdp.URLBase, .browserContextId = BrowserContextID, }, @@ -185,7 +185,7 @@ fn attachToTarget( sessionId: []const u8, }; const output = SessionId{ - .sessionId = input.sessionId orelse BrowserContextID, + .sessionId = input.sessionId orelse cdp.BrowserSessionID, }; return result(alloc, input.id, SessionId, output, null); } @@ -342,6 +342,7 @@ fn createTarget( ctx.state.securityOrigin = "://"; ctx.state.secureContextType = "InsecureScheme"; ctx.state.loaderID = LoaderID; + ctx.state.sessionID = msg.sessionId; // send targetCreated event const created = TargetCreated{ @@ -361,9 +362,10 @@ fn createTarget( .sessionId = cdp.ContextSessionID, .targetInfo = .{ .targetId = ctx.state.frameID, - .title = "", + .title = "about:blank", .url = ctx.state.url, .browserContextId = input.params.browserContextId orelse ContextID, + .attached = true, }, .waitingForDebugger = true, }; diff --git a/src/server.zig b/src/server.zig index 5e83c009..89626c2e 100644 --- a/src/server.zig +++ b/src/server.zig @@ -347,7 +347,7 @@ pub const Ctx = struct { const s = try std.fmt.allocPrint( allocator, tpl, - .{ msg_open, cdp.ContextSessionID }, + .{ msg_open, ctx.state.sessionID orelse cdp.ContextSessionID }, ); try ctx.send(s);