From 84c5730b6a875e4ac5b402e281c115f362414bfc Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Sun, 5 Jul 2026 15:40:58 +0200 Subject: [PATCH] singlefile: force --window-size=1920,1080 for viewport-dependent CSS preservation Add --window-size=1920,1080 to the Chromium flags passed via --browser-args. This makes the existing --remove-unused-styles=false and --remove-alternative-medias=false effective for real @media rules and responsive styles (headless default is small). Also document in ARCHIVR_CHROME_ARGS that users can override by supplying their own --window-size in the env var. --- crates/archivr-core/src/downloader/singlefile.rs | 7 +++++++ docs/README.md | 3 +++ 2 files changed, 10 insertions(+) diff --git a/crates/archivr-core/src/downloader/singlefile.rs b/crates/archivr-core/src/downloader/singlefile.rs index 4e19110..db27845 100644 --- a/crates/archivr-core/src/downloader/singlefile.rs +++ b/crates/archivr-core/src/downloader/singlefile.rs @@ -72,9 +72,16 @@ fn save_with( // then append any extra flags from ARCHIVR_CHROME_ARGS (space-separated). // Docker containers running as root need "--no-sandbox" here because // Chromium refuses to start as root without it. + // + // --window-size is set to a realistic desktop viewport so that + // --remove-alternative-medias=false and --remove-unused-styles=false + // actually preserve responsive @media rules and styles that only match + // at normal screen widths (headless Chromium defaults to a small viewport + // that would otherwise defeat the preservation flags). let mut chrome_flags = vec![ "--disable-web-security".to_string(), format!("--user-data-dir={}", chrome_data_dir.display()), + "--window-size=1920,1080".to_string(), ]; if let Ok(extra) = std::env::var("ARCHIVR_CHROME_ARGS") { chrome_flags.extend(extra.split_whitespace().filter(|s| !s.is_empty()).map(str::to_string)); diff --git a/docs/README.md b/docs/README.md index 6855fec..0f69323 100644 --- a/docs/README.md +++ b/docs/README.md @@ -314,6 +314,9 @@ dependencies (Chromium, Node.js, Python) land in the final layer. - Space-separated extra flags appended to Chromium's `--browser-args`. The Docker image sets this to `--no-sandbox` because Chromium refuses to run as root without it. Leave unset when running natively (Nix, Linux desktop). + A `--window-size=1920,1080` is always passed to provide a realistic desktop + viewport (so responsive @media rules and styles are evaluated and preserved + correctly). Supply your own `--window-size=...` here to override. - `ARCHIVR_TWITTER_CREDENTIALS_FILE` - Required for tweet/thread scraping inputs such as `tweet:ID` and `x:thread:ID`. - Must point to a cookies file for the vendored scraper.