Add target.getBrowserContexts

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-06-07 16:02:02 +02:00
parent dc1456f4e8
commit fa82160265

View File

@@ -10,6 +10,7 @@ const stringify = cdp.stringify;
const TargetMethods = enum { const TargetMethods = enum {
setAutoAttach, setAutoAttach,
getTargetInfo, getTargetInfo,
getBrowserContexts,
createBrowserContext, createBrowserContext,
createTarget, createTarget,
}; };
@@ -26,6 +27,7 @@ pub fn target(
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),
.getBrowserContexts => getBrowserContexts(alloc, id, scanner, ctx),
.createBrowserContext => createBrowserContext(alloc, id, scanner, ctx), .createBrowserContext => createBrowserContext(alloc, id, scanner, ctx),
.createTarget => createTarget(alloc, id, scanner, ctx), .createTarget => createTarget(alloc, id, scanner, ctx),
}; };
@@ -118,6 +120,32 @@ fn tagetGetTargetInfo(
return result(alloc, id orelse msg.id.?, TargetInfo, targetInfo, null); return result(alloc, id orelse msg.id.?, TargetInfo, targetInfo, null);
} }
// Browser context are not handled and not in the roadmap for now
// The following methods are "fake"
fn getBrowserContexts(
alloc: std.mem.Allocator,
id: ?u16,
scanner: *std.json.Scanner,
ctx: *Ctx,
) ![]const u8 {
const msg = try getMsg(alloc, void, scanner);
// ouptut
const Resp = struct {
browserContextIds: [][]const u8,
};
var resp: Resp = undefined;
if (ctx.state.contextID) |contextID| {
var contextIDs = [1][]const u8{contextID};
resp = .{ .browserContextIds = &contextIDs };
} else {
const contextIDs = [0][]const u8{};
resp = .{ .browserContextIds = &contextIDs };
}
return result(alloc, id orelse msg.id.?, Resp, resp, null);
}
const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89"; const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89";
const ContextSessionID = "4FDC2CB760A23A220497A05C95417CF4"; const ContextSessionID = "4FDC2CB760A23A220497A05C95417CF4";