Add Target.getTargetInfo

+ do not send attachedToTarget if sessionId

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-04-18 13:20:23 +02:00
parent 69f5bb9ed3
commit 06f161c423
3 changed files with 39 additions and 30 deletions

View File

@@ -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);
}