Skip to content

Commit

Permalink
Merge pull request #287 from lightpanda-io/cdp-attach-to-target
Browse files Browse the repository at this point in the history
cdp: add Target.attachToTarget noop
  • Loading branch information
francisbouvier authored Nov 7, 2024
2 parents 3af34d1 + 60adf0a commit ec5de2f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/cdp/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const log = std.log.scoped(.cdp);
const Methods = enum {
setDiscoverTargets,
setAutoAttach,
attachToTarget,
getTargetInfo,
getBrowserContexts,
createBrowserContext,
Expand All @@ -50,6 +51,7 @@ pub fn target(
return switch (method) {
.setDiscoverTargets => setDiscoverTargets(alloc, id, scanner, ctx),
.setAutoAttach => setAutoAttach(alloc, id, scanner, ctx),
.attachToTarget => attachToTarget(alloc, id, scanner, ctx),
.getTargetInfo => getTargetInfo(alloc, id, scanner, ctx),
.getBrowserContexts => getBrowserContexts(alloc, id, scanner, ctx),
.createBrowserContext => createBrowserContext(alloc, id, scanner, ctx),
Expand Down Expand Up @@ -135,6 +137,46 @@ fn setAutoAttach(
return result(alloc, msg.id, null, null, msg.sessionID);
}

// TODO: noop method
fn attachToTarget(
alloc: std.mem.Allocator,
_id: ?u16,
scanner: *std.json.Scanner,
ctx: *Ctx,
) ![]const u8 {

// input
const Params = struct {
targetId: []const u8,
flatten: bool = true,
};
const msg = try getMsg(alloc, _id, Params, scanner);
log.debug("Req > id {d}, method {s}", .{ msg.id, "target.setAutoAttach" });

// attachedToTarget event
if (msg.sessionID == null) {
const attached = AttachToTarget{
.sessionId = cdp.BrowserSessionID,
.targetInfo = .{
.targetId = PageTargetID,
.title = "New Incognito tab",
.url = cdp.URLBase,
.browserContextId = BrowserContextID,
},
};
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null);
}

// output
const SessionId = struct {
sessionId: []const u8,
};
const output = SessionId{
.sessionId = msg.sessionID orelse BrowserContextID,
};
return result(alloc, msg.id, SessionId, output, null);
}

fn getTargetInfo(
alloc: std.mem.Allocator,
_id: ?u16,
Expand Down

0 comments on commit ec5de2f

Please sign in to comment.