diff --git a/apps/chuzz/src/capture.rs b/apps/chuzz/src/capture.rs index 7fd9ae7..1d8b0c9 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 148c97d..2565453 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 {