Skip to content

Commit 508741c

Browse files
Add Browser.getWindowForTarget
Signed-off-by: Francis Bouvier <[email protected]>
1 parent f02de77 commit 508741c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/cdp/browser.zig

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ const std = @import("std");
22

33
const server = @import("../server.zig");
44
const Ctx = server.Cmd;
5-
const result = @import("cdp.zig").result;
6-
const getParams = @import("cdp.zig").getParams;
5+
const cdp = @import("cdp.zig");
6+
const result = cdp.result;
7+
const getParams = cdp.getParams;
78

89
const BrowserMethods = enum {
910
getVersion,
1011
setDownloadBehavior,
12+
getWindowForTarget,
1113
};
1214

1315
pub fn browser(
@@ -22,6 +24,7 @@ pub fn browser(
2224
return switch (method) {
2325
.getVersion => browserGetVersion(alloc, id, scanner, ctx),
2426
.setDownloadBehavior => browserSetDownloadBehavior(alloc, id, scanner, ctx),
27+
.getWindowForTarget => getWindowForTarget(alloc, id, scanner, ctx),
2528
};
2629
}
2730

@@ -70,3 +73,33 @@ fn browserSetDownloadBehavior(
7073
_ = try getParams(alloc, Params, scanner);
7174
return result(alloc, id, null, null, null);
7275
}
76+
77+
const DevToolsWindowID = 1923710101;
78+
79+
fn getWindowForTarget(
80+
alloc: std.mem.Allocator,
81+
id: u64,
82+
scanner: *std.json.Scanner,
83+
_: *Ctx,
84+
) ![]const u8 {
85+
86+
// input
87+
const Params = struct {
88+
targetId: ?[]const u8 = null,
89+
};
90+
const content = try cdp.getContent(alloc, ?Params, scanner);
91+
std.debug.assert(content.sessionID != null);
92+
93+
// output
94+
const Resp = struct {
95+
windowId: u64 = DevToolsWindowID,
96+
bounds: struct {
97+
left: ?u64 = null,
98+
top: ?u64 = null,
99+
width: ?u64 = null,
100+
height: ?u64 = null,
101+
windowState: []const u8 = "normal",
102+
} = .{},
103+
};
104+
return result(alloc, id, Resp, Resp{}, content.sessionID.?);
105+
}

0 commit comments

Comments
 (0)