mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-08-02 18:59:36 -04:00
Merge pull request #2971 from lightpanda-io/cdp-expose-lightpanda-version
cdp: expose lightpanda version
This commit is contained in:
@@ -283,6 +283,7 @@ fn buildJSONVersionResponse(app: *const App, port: u16) ![]const u8 {
|
||||
"\"Browser\": \"Lightpanda/1.0\", " ++
|
||||
"\"Protocol-Version\": \"1.3\", " ++
|
||||
"\"User-Agent\": \"Lightpanda/1.0\", " ++
|
||||
"\"Lightpanda-Version\": \"" ++ lp.build_config.version ++ "\", " ++
|
||||
"\"webSocketDebuggerUrl\": \"ws://{s}:{d}/\"" ++
|
||||
"}}";
|
||||
const body_len = std.fmt.count(body_format, .{ host, port });
|
||||
@@ -316,6 +317,7 @@ test "server: buildJSONVersionResponse" {
|
||||
try testing.expect(std.mem.indexOf(u8, res, "\"Browser\": \"Lightpanda/") != null);
|
||||
try testing.expect(std.mem.indexOf(u8, res, "\"Protocol-Version\": \"1.3\"") != null);
|
||||
try testing.expect(std.mem.indexOf(u8, res, "\"User-Agent\": \"Lightpanda/") != null);
|
||||
try testing.expect(std.mem.indexOf(u8, res, "\"Lightpanda-Version\": \"" ++ lp.build_config.version ++ "\"") != null);
|
||||
try testing.expect(std.mem.indexOf(u8, res, "\"webSocketDebuggerUrl\": \"ws://127.0.0.1:9222/\"") != null);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ pub fn processMessage(cmd: *CDP.Command) !void {
|
||||
waitForSelector,
|
||||
handleJavaScriptDialog,
|
||||
configureLoading,
|
||||
version,
|
||||
}, cmd.input.action) orelse return error.UnknownMethod;
|
||||
|
||||
switch (action) {
|
||||
@@ -61,9 +62,16 @@ pub fn processMessage(cmd: *CDP.Command) !void {
|
||||
.waitForSelector => return waitForSelector(cmd),
|
||||
.handleJavaScriptDialog => return handleJavaScriptDialog(cmd),
|
||||
.configureLoading => return configureLoading(cmd),
|
||||
.version => return version(cmd),
|
||||
}
|
||||
}
|
||||
|
||||
fn version(cmd: *CDP.Command) !void {
|
||||
return cmd.sendResult(.{
|
||||
.version = lp.build_config.version,
|
||||
}, .{});
|
||||
}
|
||||
|
||||
fn configureLoading(cmd: *CDP.Command) !void {
|
||||
// Each field is optional so callers can flip one without resetting
|
||||
// the other to its default. Backwards-compatible: existing callers
|
||||
@@ -386,6 +394,19 @@ fn handleJavaScriptDialog(cmd: anytype) !void {
|
||||
}
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
test "cdp.lp: version" {
|
||||
var ctx = try testing.context();
|
||||
defer ctx.deinit();
|
||||
|
||||
try ctx.processMessage(.{
|
||||
.id = 1,
|
||||
.method = "LP.version",
|
||||
});
|
||||
|
||||
const result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
|
||||
try testing.expectEqualSlices(u8, lp.build_config.version, result.get("version").?.string);
|
||||
}
|
||||
|
||||
test "cdp.lp: getMarkdown" {
|
||||
var ctx = try testing.context();
|
||||
defer ctx.deinit();
|
||||
|
||||
Reference in New Issue
Block a user