From e6af7abbd8b9d6ca07fb51c9cf1dc6128e7b17d6 Mon Sep 17 00:00:00 2001 From: meh Date: Mon, 31 Aug 2026 16:30:28 +0700 Subject: [PATCH] fix(capture): honour the capture viewport environment variables `scripts/render-check.sh` has documented and exported CHUZZ_CAPTURE_WIDTH and CHUZZ_CAPTURE_HEIGHT since it was written, and the capture entry point read neither: it passed a literal 1440 by 960. Every capture was that size whatever the caller asked for, and a run at another width produced a byte-identical tree, which is how this surfaced. That matters now because captures are about to be compared against a reference browser. Two engines laying the same page out at different widths disagree on every percentage width, every centred box and every responsive breakpoint, so an unhonoured viewport turns a diff into noise that reads exactly like a rendering fault. Only CHUZZ_CAPTURE_SCALE was wired up, so the fix follows its shape. --- apps/chuzz/src/capture.rs | 23 +++++++++++++++++++++++ apps/chuzz/src/tauri_main.rs | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/chuzz/src/capture.rs b/apps/chuzz/src/capture.rs index 7fd9ae79..1d8b0c92 100644 --- a/apps/chuzz/src/capture.rs +++ b/apps/chuzz/src/capture.rs @@ -45,6 +45,29 @@ fn capture_scale() -> f32 { .unwrap_or(1.0) } +/// CSS pixel size to lay the page out at. Defaults to 1440 by 960. +/// +/// A capture is only comparable against a reference browser when both laid the +/// page out at the same width: every responsive breakpoint, every percentage +/// width and every centred box moves with it. These were exported by +/// `scripts/render-check.sh` and read by nothing, so a run at another size +/// silently produced the default and the resulting diff was all viewport and +/// no signal. +pub fn capture_viewport() -> (u32, u32) { + fn dimension(name: &str, fallback: u32) -> u32 { + std::env::var(name) + .ok() + .and_then(|value| value.parse().ok()) + .filter(|pixels: &u32| *pixels > 0) + .unwrap_or(fallback) + } + + ( + dimension("CHUZZ_CAPTURE_WIDTH", 1440), + dimension("CHUZZ_CAPTURE_HEIGHT", 960), + ) +} + /// Which colour scheme to render at. Defaults to dark. /// /// A site that respects `prefers-color-scheme` is a different page in each, so diff --git a/apps/chuzz/src/tauri_main.rs b/apps/chuzz/src/tauri_main.rs index 148c97d5..25654530 100644 --- a/apps/chuzz/src/tauri_main.rs +++ b/apps/chuzz/src/tauri_main.rs @@ -186,10 +186,11 @@ fn main() { .enable_all() .build() .expect("capture needs a tokio runtime"); + let (width, height) = capture::capture_viewport(); let result = runtime.block_on(capture::capture( &url, - 1440, - 960, + width, + height, std::path::Path::new(&output), )); match result {