From 92ef2798d252a5e6da94c1c593414b283eadd5eb Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Sun, 10 Aug 2025 04:46:20 +0400 Subject: [PATCH] feat: add min height and width for camoufox --- nodecar/src/camoufox-launcher.ts | 22 ++++++++++---- nodecar/src/index.ts | 10 +++++++ src-tauri/src/camoufox.rs | 16 ++++++++++ .../shared-camoufox-config-form.tsx | 30 +++++++++++++++++++ src/types.ts | 2 ++ 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/nodecar/src/camoufox-launcher.ts b/nodecar/src/camoufox-launcher.ts index 3a20c6a..af77272 100644 --- a/nodecar/src/camoufox-launcher.ts +++ b/nodecar/src/camoufox-launcher.ts @@ -344,6 +344,8 @@ interface GenerateConfigOptions { proxy?: string; maxWidth?: number; maxHeight?: number; + minWidth?: number; + minHeight?: number; geoip?: string | boolean; blockImages?: boolean; blockWebrtc?: boolean; @@ -411,11 +413,21 @@ export async function generateCamoufoxConfig( } else { // Use individual options to build configuration - if (options.maxWidth && options.maxHeight) { - launchOpts.screen = { - maxWidth: options.maxWidth, - maxHeight: options.maxHeight, - }; + // Build screen configuration with min/max dimensions + const screen: { + minWidth?: number; + maxWidth?: number; + minHeight?: number; + maxHeight?: number; + } = {}; + + if (options.minWidth) screen.minWidth = options.minWidth; + if (options.maxWidth) screen.maxWidth = options.maxWidth; + if (options.minHeight) screen.minHeight = options.minHeight; + if (options.maxHeight) screen.maxHeight = options.maxHeight; + + if (Object.keys(screen).length > 0) { + launchOpts.screen = screen; } } diff --git a/nodecar/src/index.ts b/nodecar/src/index.ts index 96e9fff..0facc98 100644 --- a/nodecar/src/index.ts +++ b/nodecar/src/index.ts @@ -165,6 +165,8 @@ program .option("--proxy ", "proxy URL for config generation") .option("--max-width ", "maximum screen width", parseInt) .option("--max-height ", "maximum screen height", parseInt) + .option("--min-width ", "minimum screen width", parseInt) + .option("--min-height ", "minimum screen height", parseInt) .option("--geoip", "enable geoip") .option("--block-images", "block images") .option("--block-webrtc", "block WebRTC") @@ -384,6 +386,14 @@ program typeof options.maxHeight === "number" ? options.maxHeight : undefined, + minWidth: + typeof options.minWidth === "number" + ? options.minWidth + : undefined, + minHeight: + typeof options.minHeight === "number" + ? options.minHeight + : undefined, geoip: Boolean(options.geoip), blockImages: typeof options.blockImages === "boolean" diff --git a/src-tauri/src/camoufox.rs b/src-tauri/src/camoufox.rs index a6a9956..3274ebe 100644 --- a/src-tauri/src/camoufox.rs +++ b/src-tauri/src/camoufox.rs @@ -12,6 +12,8 @@ pub struct CamoufoxConfig { pub proxy: Option, pub screen_max_width: Option, pub screen_max_height: Option, + pub screen_min_width: Option, + pub screen_min_height: Option, pub geoip: Option, // Can be String or bool pub block_images: Option, pub block_webrtc: Option, @@ -26,6 +28,8 @@ impl Default for CamoufoxConfig { proxy: None, screen_max_width: None, screen_max_height: None, + screen_min_width: None, + screen_min_height: None, geoip: Some(serde_json::Value::Bool(true)), block_images: None, block_webrtc: None, @@ -83,6 +87,8 @@ impl CamoufoxNodecarLauncher { CamoufoxConfig { screen_max_width: Some(1440), screen_max_height: Some(900), + screen_min_width: Some(800), + screen_min_height: Some(600), geoip: Some(serde_json::Value::Bool(true)), ..Default::default() } @@ -134,6 +140,14 @@ impl CamoufoxNodecarLauncher { config_args.extend(["--max-height".to_string(), max_height.to_string()]); } + if let Some(min_width) = config.screen_min_width { + config_args.extend(["--min-width".to_string(), min_width.to_string()]); + } + + if let Some(min_height) = config.screen_min_height { + config_args.extend(["--min-height".to_string(), min_height.to_string()]); + } + // Add block_* options if let Some(block_images) = config.block_images { if block_images { @@ -477,6 +491,8 @@ mod tests { // Verify test config has expected values assert_eq!(test_config.screen_max_width, Some(1440)); assert_eq!(test_config.screen_max_height, Some(900)); + assert_eq!(test_config.screen_min_width, Some(800)); + assert_eq!(test_config.screen_min_height, Some(600)); assert_eq!(test_config.geoip, Some(serde_json::Value::Bool(true))); } diff --git a/src/components/shared-camoufox-config-form.tsx b/src/components/shared-camoufox-config-form.tsx index 72f7b1c..5527d45 100644 --- a/src/components/shared-camoufox-config-form.tsx +++ b/src/components/shared-camoufox-config-form.tsx @@ -874,6 +874,36 @@ export function SharedCamoufoxConfigForm({ placeholder="e.g., 1080" /> +
+ + + onConfigChange( + "screen_min_width", + e.target.value ? parseInt(e.target.value) : undefined, + ) + } + placeholder="e.g., 800" + /> +
+
+ + + onConfigChange( + "screen_min_height", + e.target.value ? parseInt(e.target.value) : undefined, + ) + } + placeholder="e.g., 600" + /> +
diff --git a/src/types.ts b/src/types.ts index 2b61baa..1503372 100644 --- a/src/types.ts +++ b/src/types.ts @@ -74,6 +74,8 @@ export interface CamoufoxConfig { proxy?: string; screen_max_width?: number; screen_max_height?: number; + screen_min_width?: number; + screen_min_height?: number; geoip?: string | boolean; block_images?: boolean; block_webrtc?: boolean;