From d669d5c15346c4e986b270ed0711267896b7269d Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 9 Mar 2026 16:40:57 +0100 Subject: [PATCH] cdp: add a dummy Page.getLayoutMetrics --- src/cdp/domains/page.zig | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/src/cdp/domains/page.zig b/src/cdp/domains/page.zig index d4b7b301..70f349a9 100644 --- a/src/cdp/domains/page.zig +++ b/src/cdp/domains/page.zig @@ -42,6 +42,7 @@ pub fn processMessage(cmd: anytype) !void { stopLoading, close, captureScreenshot, + getLayoutMetrics, }, cmd.input.action) orelse return error.UnknownMethod; switch (action) { @@ -54,6 +55,7 @@ pub fn processMessage(cmd: anytype) !void { .stopLoading => return cmd.sendResult(null, .{}), .close => return close(cmd), .captureScreenshot => return captureScreenshot(cmd), + .getLayoutMetrics => return getLayoutMetrics(cmd), } } @@ -569,6 +571,58 @@ fn captureScreenshot(cmd: anytype) !void { }, .{}); } +fn getLayoutMetrics(cmd: anytype) !void { + const width = 1920; + const height = 1080; + + return cmd.sendResult(.{ + .layoutViewport = .{ + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + }, + .visualViewport = .{ + .offsetX = 0, + .offsetY = 0, + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + .scale = 1, + .zoom = 1, + }, + .contentSize = .{ + .x = 0, + .y = 0, + .width = width, + .height = height, + }, + .cssLayoutViewport = .{ + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + }, + .cssVisualViewport = .{ + .offsetX = 0, + .offsetY = 0, + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + .scale = 1, + .zoom = 1, + }, + .cssContentSize = .{ + .x = 0, + .y = 0, + .width = width, + .height = height, + }, + }, .{}); +} + const testing = @import("../testing.zig"); test "cdp.page: getFrameTree" { var ctx = testing.context(); @@ -618,3 +672,61 @@ test "cdp.page: captureScreenshot" { }, .{ .id = 11 }); } } + +test "cdp.page: getLayoutMetrics" { + var ctx = testing.context(); + defer ctx.deinit(); + + _ = try ctx.loadBrowserContext(.{ .id = "BID-9", .url = "hi.html", .target_id = "FID-000000000X".* }); + + const width = 1920; + const height = 1080; + + try ctx.processMessage(.{ .id = 12, .method = "Page.getLayoutMetrics" }); + try ctx.expectSentResult(.{ + .layoutViewport = .{ + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + }, + .visualViewport = .{ + .offsetX = 0, + .offsetY = 0, + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + .scale = 1, + .zoom = 1, + }, + .contentSize = .{ + .x = 0, + .y = 0, + .width = width, + .height = height, + }, + .cssLayoutViewport = .{ + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + }, + .cssVisualViewport = .{ + .offsetX = 0, + .offsetY = 0, + .pageX = 0, + .pageY = 0, + .clientWidth = width, + .clientHeight = height, + .scale = 1, + .zoom = 1, + }, + .cssContentSize = .{ + .x = 0, + .y = 0, + .width = width, + .height = height, + }, + }, .{ .id = 12 }); +}