cdp: add LP domain and getMarkdown method

This PR introduces a custom CDP domain 'LP' (Lightpanda) to expose browser-specific tools. The first method, 'LP.getMarkdown', allows retrieving a Markdown representation of the DOM or a specific node by its 'nodeId'. This is optimized for AI agents and LLM-based scraping tasks.
This commit is contained in:
Adrià Arrufat
2026-03-03 16:11:31 +09:00
parent cce533ebb6
commit cc93180d57
2 changed files with 79 additions and 0 deletions

View File

@@ -219,6 +219,10 @@ pub fn CDPT(comptime TypeProvider: type) type {
};
switch (domain.len) {
2 => switch (@as(u16, @bitCast(domain[0..2].*))) {
asUint(u16, "LP") => return @import("domains/lp.zig").processMessage(command),
else => {},
},
3 => switch (@as(u24, @bitCast(domain[0..3].*))) {
asUint(u24, "DOM") => return @import("domains/dom.zig").processMessage(command),
asUint(u24, "Log") => return @import("domains/log.zig").processMessage(command),
@@ -978,3 +982,19 @@ test "cdp: STARTUP sessionId" {
try ctx.expectSentResult(null, .{ .id = 4, .index = 0, .session_id = "STARTUP" });
}
}
test "cdp: LP.getMarkdown" {
var ctx = testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
_ = try bc.session.createPage();
try ctx.processMessage(.{
.id = 1,
.method = "LP.getMarkdown",
});
const result = ctx.client.?.sent.items[0].object.get("result").?.object;
try testing.expect(result.get("markdown") != null);
}