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

@@ -190,3 +190,5 @@ pub fn getSessionID(scanner: *std.json.Scanner) !?[]const u8 {
// ------ // ------
pub const SessionID = "9559320D92474062597D9875C664CAC0"; pub const SessionID = "9559320D92474062597D9875C664CAC0";
pub const URLBase = "chrome://newtab/";
pub const FrameID = "90D14BBD8AED408A0467AC93100BCDBE";

View File

@@ -41,9 +41,7 @@ fn enable(
return result(alloc, id, null, null, sessionID); return result(alloc, id, null, null, sessionID);
} }
const FrameTreeID = "90D14BBD8AED408A0467AC93100BCDBE";
const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C"; const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C";
const URLBase = "chrome://newtab/";
fn getFrameTree( fn getFrameTree(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
@@ -55,11 +53,11 @@ fn getFrameTree(
const FrameTree = struct { const FrameTree = struct {
frameTree: struct { frameTree: struct {
frame: struct { frame: struct {
id: []const u8 = FrameTreeID, id: []const u8 = cdp.FrameID,
loaderId: []const u8 = LoaderID, loaderId: []const u8 = LoaderID,
url: []const u8 = URLBase, url: []const u8 = cdp.URLBase,
domainAndRegistry: []const u8 = "", domainAndRegistry: []const u8 = "",
securityOrigin: []const u8 = URLBase, securityOrigin: []const u8 = cdp.URLBase,
mimeType: []const u8 = "mimeType", mimeType: []const u8 = "mimeType",
adFrameStatus: struct { adFrameStatus: struct {
adFrameType: []const u8 = "none", adFrameType: []const u8 = "none",

View File

@@ -9,7 +9,7 @@ const stringify = cdp.stringify;
const TargetMethods = enum { const TargetMethods = enum {
setAutoAttach, setAutoAttach,
// getTargetInfo, getTargetInfo,
}; };
pub fn target( pub fn target(
@@ -23,12 +23,12 @@ pub fn target(
return error.UnknownMethod; return error.UnknownMethod;
return switch (method) { return switch (method) {
.setAutoAttach => tagetSetAutoAttach(alloc, id, scanner, ctx), .setAutoAttach => tagetSetAutoAttach(alloc, id, scanner, ctx),
// .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner, ctx), .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner, ctx),
}; };
} }
const SessionID = "9559320D92474062597D9875C664CAC0"; const PageTargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC";
const TargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; const BrowserTargetID = "2d2bdef9-1c95-416f-8c0e-83f3ab73a30c";
const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9"; const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9";
const TargetFilter = struct { const TargetFilter = struct {
@@ -51,26 +51,28 @@ fn tagetSetAutoAttach(
const params = try getParams(alloc, Params, scanner); const params = try getParams(alloc, Params, scanner);
std.log.debug("params {any}", .{params}); std.log.debug("params {any}", .{params});
const AttachToTarget = struct { const sessionID = try cdp.getSessionID(scanner);
method: []const u8 = "Target.attachedToTarget",
params: struct { if (sessionID == null) {
sessionId: []const u8 = SessionID, const AttachToTarget = struct {
sessionId: []const u8 = cdp.SessionID,
targetInfo: struct { targetInfo: struct {
targetId: []const u8 = TargetID, targetId: []const u8 = PageTargetID,
type: []const u8 = "page", type: []const u8 = "page",
title: []const u8 = "New Incognito tab", title: []const u8 = "New Incognito tab",
url: []const u8 = "chrome://newtab/", url: []const u8 = cdp.URLBase,
attached: bool = true, attached: bool = true,
canAccessOpener: bool = false, canAccessOpener: bool = false,
browserContextId: []const u8 = BrowserContextID, browserContextId: []const u8 = BrowserContextID,
} = .{}, } = .{},
waitingForDebugger: bool = false, waitingForDebugger: bool = false,
} = .{}, };
}; const attached = try cdp.method(alloc, "Target.attachedToTarget", AttachToTarget, .{}, null);
const attached = try stringify(alloc, AttachToTarget{}); std.log.debug("res {s}", .{attached});
try server.sendSync(ctx, attached); try server.sendSync(ctx, attached);
}
return result(alloc, id, null, null, null); return result(alloc, id, null, null, sessionID);
} }
fn tagetGetTargetInfo( fn tagetGetTargetInfo(
@@ -79,22 +81,29 @@ fn tagetGetTargetInfo(
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
_ = scanner;
// input
const Params = struct {
targetId: ?[]const u8 = null,
};
_ = try getParams(alloc, Params, scanner);
// output
const TargetInfo = struct { const TargetInfo = struct {
targetId: []const u8, targetId: []const u8,
type: []const u8, type: []const u8,
title: []const u8, title: []const u8 = "",
url: []const u8, url: []const u8 = "",
attached: bool, attached: bool = true,
canAccessOpener: bool, openerId: ?[]const u8 = null,
canAccessOpener: bool = false,
openerFrameId: ?[]const u8 = null,
browserContextId: ?[]const u8 = null, browserContextId: ?[]const u8 = null,
subtype: ?[]const u8 = null,
}; };
const targetInfo = TargetInfo{ const targetInfo = TargetInfo{
.targetId = TargetID, .targetId = BrowserTargetID,
.type = "page", .type = "browser",
}; };
_ = targetInfo; return result(alloc, id, TargetInfo, targetInfo, null);
return result(alloc, id, null, null);
} }