server: implement /json/list

Mimic Chrome's endpoints to enable Selenium CDP connection.
This commit is contained in:
Pierre Tachoire
2025-02-13 17:16:32 +01:00
parent d8fae5bc41
commit ea19f7e348

View File

@@ -578,6 +578,16 @@ fn Client(comptime S: type) type {
return self.send(self.server.json_version_response, false);
}
const json_list_response =
"HTTP/1.1 200 OK\r\n" ++
"Content-Length: 47\r\n" ++
"Content-Type: application/json; charset=UTF-8\r\n\r\n" ++
"[{\"id\":\"1\",\"type\":\"page\",\"url\":\"abount:blank\"}]";
if (std.mem.eql(u8, url, "/json/list")) {
return self.send(json_list_response, false);
}
return error.NotFound;
}
@@ -1123,12 +1133,12 @@ pub fn run(
// Utils
// --------
//
fn buildJSONVersionResponse(
allocator: Allocator,
address: net.Address,
) ![]const u8 {
const body_format = "{{\"webSocketDebuggerUrl\": \"ws://{}/\"}}";
const body_format = "{{\"Browser\": \"Chrome/132.0.6834.110\", \"WebKit-Version\": \"537.36 (@df453a35f099772fdb954e33551388add2ca3cde)\", \"webSocketDebuggerUrl\": \"ws://{}/\"}}";
const body_len = std.fmt.count(body_format, .{address});
const response_format =