fix: use custom viewport dimensions in streaming frame metadata and image resolution (#1033)
* fix: use custom viewport dimensions in streaming frame metadata CDP's Page.screencastFrame metadata returns physical device dimensions instead of the emulated viewport, causing frame messages to report incorrect deviceWidth/deviceHeight when a custom viewport is set. Use the viewport dimensions captured at screencast start instead of the CDP metadata values, since the screencast image is already captured at the configured viewport size. Closes #1031 * fix: resize browser content area on viewport change for correct screencast dimensions Emulation.setDeviceMetricsOverride only changes the CSS viewport, but screencast captures the actual browser content area. This caused frame images to have incorrect dimensions (e.g., 1000x451 instead of 1000x1000) when a custom viewport was set. - Call Browser.setContentsSize after setDeviceMetricsOverride so the content area matches the emulated viewport - Restart active screencast when viewport dimensions change so maxWidth/maxHeight parameters are updated - Skip redundant screencast restarts when dimensions are unchanged - Extend E2E test to verify actual JPEG image dimensions, not just metadata * fix: pass viewport dimensions to --window-size at launch and log setContentsSize failures - Add viewport_size to LaunchOptions so --window-size matches the configured viewport from the start, reducing reliance on the experimental Browser.setContentsSize CDP call at runtime - Log Browser.setContentsSize failures instead of silently ignoring them with let _ = * fix: remove duplicate viewport change detection block (dead code from merge) * fix: use log::debug! instead of eprintln! for setContentsSize failure * revert: use eprintln! instead of log crate for setContentsSize failure The daemon's stderr pipe is closed after startup, so log crate subscribers cannot output during normal operation. eprintln! is visible during startup and in tests, matching the existing convention. --------- Co-authored-by: hyunjinee <leehj0110@kakao.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
hyunjinee
Claude Opus 4.6
parent
6520e4123c
commit
2164e71c30
@@ -103,6 +103,9 @@ pub struct LaunchOptions {
|
||||
pub ignore_https_errors: bool,
|
||||
pub color_scheme: Option<String>,
|
||||
pub download_path: Option<String>,
|
||||
/// Initial viewport dimensions used for `--window-size` so the content
|
||||
/// area matches the desired viewport from the start.
|
||||
pub viewport_size: Option<(u32, u32)>,
|
||||
/// When true, omit `--password-store=basic` and `--use-mock-keychain` so
|
||||
/// Chrome uses the real system keychain. Set automatically when launching
|
||||
/// with a copied Chrome profile.
|
||||
@@ -127,6 +130,7 @@ impl Default for LaunchOptions {
|
||||
ignore_https_errors: false,
|
||||
color_scheme: None,
|
||||
download_path: None,
|
||||
viewport_size: None,
|
||||
use_real_keychain: false,
|
||||
}
|
||||
}
|
||||
@@ -222,7 +226,8 @@ fn build_chrome_args(options: &LaunchOptions) -> Result<ChromeArgs, String> {
|
||||
.any(|a| a.starts_with("--start-maximized") || a.starts_with("--window-size="));
|
||||
|
||||
if !has_window_size && options.headless && !has_extensions {
|
||||
args.push("--window-size=1280,720".to_string());
|
||||
let (w, h) = options.viewport_size.unwrap_or((1280, 720));
|
||||
args.push(format!("--window-size={},{}", w, h));
|
||||
}
|
||||
|
||||
args.extend(options.args.iter().cloned());
|
||||
|
||||
Reference in New Issue
Block a user