Skip to content

Commit 60adf0a

Browse files
committed
cdp: add Target.attachToTarget noop
1 parent 826f826 commit 60adf0a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/cdp/target.zig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const log = std.log.scoped(.cdp);
3030
const Methods = enum {
3131
setDiscoverTargets,
3232
setAutoAttach,
33+
attachToTarget,
3334
getTargetInfo,
3435
getBrowserContexts,
3536
createBrowserContext,
@@ -50,6 +51,7 @@ pub fn target(
5051
return switch (method) {
5152
.setDiscoverTargets => setDiscoverTargets(alloc, id, scanner, ctx),
5253
.setAutoAttach => setAutoAttach(alloc, id, scanner, ctx),
54+
.attachToTarget => attachToTarget(alloc, id, scanner, ctx),
5355
.getTargetInfo => getTargetInfo(alloc, id, scanner, ctx),
5456
.getBrowserContexts => getBrowserContexts(alloc, id, scanner, ctx),
5557
.createBrowserContext => createBrowserContext(alloc, id, scanner, ctx),
@@ -135,6 +137,46 @@ fn setAutoAttach(
135137
return result(alloc, msg.id, null, null, msg.sessionID);
136138
}
137139

140+
// TODO: noop method
141+
fn attachToTarget(
142+
alloc: std.mem.Allocator,
143+
_id: ?u16,
144+
scanner: *std.json.Scanner,
145+
ctx: *Ctx,
146+
) ![]const u8 {
147+
148+
// input
149+
const Params = struct {
150+
targetId: []const u8,
151+
flatten: bool = true,
152+
};
153+
const msg = try getMsg(alloc, _id, Params, scanner);
154+
log.debug("Req > id {d}, method {s}", .{ msg.id, "target.setAutoAttach" });
155+
156+
// attachedToTarget event
157+
if (msg.sessionID == null) {
158+
const attached = AttachToTarget{
159+
.sessionId = cdp.BrowserSessionID,
160+
.targetInfo = .{
161+
.targetId = PageTargetID,
162+
.title = "New Incognito tab",
163+
.url = cdp.URLBase,
164+
.browserContextId = BrowserContextID,
165+
},
166+
};
167+
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null);
168+
}
169+
170+
// output
171+
const SessionId = struct {
172+
sessionId: []const u8,
173+
};
174+
const output = SessionId{
175+
.sessionId = msg.sessionID orelse BrowserContextID,
176+
};
177+
return result(alloc, msg.id, SessionId, output, null);
178+
}
179+
138180
fn getTargetInfo(
139181
alloc: std.mem.Allocator,
140182
_id: ?u16,

0 commit comments

Comments
 (0)