Skip to content

Lightpanda: the headless browser designed for AI and automation

cdp: echo the sessionId in replies to browser-level commands

Celine Debledc98afa4bebd3
diff --git a/src/server/cdp/CDP.zig b/src/server/cdp/CDP.zig
index b7e0d560e..aa44fbe16 100644
--- a/src/server/cdp/CDP.zig
+++ b/src/server/cdp/CDP.zig
@@ -1397,14 +1397,12 @@ pub const Command = struct {
return self.browser_context.?;
}
- const SendResultOpts = struct {
- include_session_id: bool = true,
- };
- pub fn sendResult(self: *Command, result: anytype, opts: SendResultOpts) !void {
+ const SendResultOpts = struct {};
+ pub fn sendResult(self: *Command, result: anytype, _: SendResultOpts) !void {
return self.sender.sendJSON(.{
.id = self.input.id,
.result = if (comptime @typeInfo(@TypeOf(result)) == .null) struct {}{} else result,
- .sessionId = if (opts.include_session_id) self.input.session_id else null,
+ .sessionId = self.input.session_id,
});
}
@@ -1413,14 +1411,12 @@ pub const Command = struct {
return self.cdp.sendEvent(method, p, opts);
}
- const SendErrorOpts = struct {
- include_session_id: bool = true,
- };
- pub fn sendError(self: *Command, code: i32, message: []const u8, opts: SendErrorOpts) !void {
+ const SendErrorOpts = struct {};
+ pub fn sendError(self: *Command, code: i32, message: []const u8, _: SendErrorOpts) !void {
return self.sender.sendJSON(.{
.id = self.input.id,
.@"error" = .{ .code = code, .message = message },
- .sessionId = if (opts.include_session_id) self.input.session_id else null,
+ .sessionId = self.input.session_id,
});
}
diff --git a/src/server/cdp/domains/browser.zig b/src/server/cdp/domains/browser.zig
index 4ebc03408..1cf61c269 100644
--- a/src/server/cdp/domains/browser.zig
+++ b/src/server/cdp/domains/browser.zig
@@ -74,7 +74,7 @@ fn getVersion(cmd: *CDP.Command) !void {
.revision = REVISION,
.userAgent = CDP_USER_AGENT,
.jsVersion = JS_VERSION,
- }, .{ .include_session_id = false });
+ }, .{});
}
// https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-setDownloadBehavior
@@ -195,7 +195,7 @@ fn grantPermissions(cmd: *CDP.Command) !void {
try browser.setPermission(name, .granted);
}
- return cmd.sendResult(null, .{ .include_session_id = false });
+ return cmd.sendResult(null, .{});
}
// Set a single permission to an explicit state ("granted", "denied" or
@@ -219,14 +219,14 @@ fn setPermission(cmd: *CDP.Command) !void {
return error.InvalidPermissionSetting;
};
try cmd.cdp.browser.setPermission(params.permission.name, state);
- return cmd.sendResult(null, .{ .include_session_id = false });
+ return cmd.sendResult(null, .{});
}
// Clear all granted permissions; navigator.permissions.query() falls back to
// the default "prompt".
fn resetPermissions(cmd: *CDP.Command) !void {
cmd.cdp.browser.clearPermissions();
- return cmd.sendResult(null, .{ .include_session_id = false });
+ return cmd.sendResult(null, .{});
}
const testing = @import("../testing.zig");
diff --git a/src/server/cdp/domains/target.zig b/src/server/cdp/domains/target.zig
index 0e906a37c..d5162d0eb 100644
--- a/src/server/cdp/domains/target.zig
+++ b/src/server/cdp/domains/target.zig
@@ -68,13 +68,13 @@ fn getTargets(cmd: *CDP.Command) !void {
const bc = cmd.browser_context orelse {
return cmd.sendResult(.{
.targetInfos = [_]TargetInfo{},
- }, .{ .include_session_id = false });
+ }, .{});
};
const target_id = &(bc.target_id orelse {
return cmd.sendResult(.{
.targetInfos = [_]TargetInfo{},
- }, .{ .include_session_id = false });
+ }, .{});
});
return cmd.sendResult(.{
@@ -86,7 +86,7 @@ fn getTargets(cmd: *CDP.Command) !void {
.attached = true,
.canAccessOpener = false,
}},
- }, .{ .include_session_id = false });
+ }, .{});
}
fn getBrowserContexts(cmd: *CDP.Command) !void {
@@ -99,7 +99,7 @@ fn getBrowserContexts(cmd: *CDP.Command) !void {
return cmd.sendResult(.{
.browserContextIds = browser_context_ids,
- }, .{ .include_session_id = false });
+ }, .{});
}
fn createBrowserContext(cmd: *CDP.Command) !void {
@@ -316,7 +316,7 @@ fn closeTarget(cmd: *CDP.Command) !void {
// can't be null if we have a target_id
lp.assert(bc.session.hasPage(), "CDP.target.closeTarget null frame", .{});
- try cmd.sendResult(.{ .success = true }, .{ .include_session_id = false });
+ try cmd.sendResult(.{ .success = true }, .{});
for (bc.attached_sessions.items) |session| {
bc.fetchDisableForSession(session.id);
@@ -382,7 +382,7 @@ fn getTargetInfo(cmd: *CDP.Command) !void {
.attached = true,
.canAccessOpener = false,
},
- }, .{ .include_session_id = false });
+ }, .{});
}
return cmd.sendResult(.{
@@ -394,7 +394,7 @@ fn getTargetInfo(cmd: *CDP.Command) !void {
.attached = true,
.canAccessOpener = false,
},
- }, .{ .include_session_id = false });
+ }, .{});
}
fn sendMessageToTarget(cmd: *CDP.Command) !void {