"use client"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import type { BrowserProfile, CamoufoxConfig } from "@/types"; interface CamoufoxConfigDialogProps { isOpen: boolean; onClose: () => void; profile: BrowserProfile | null; onSave: (profile: BrowserProfile, config: CamoufoxConfig) => Promise; } const osOptions = [ { value: "windows", label: "Windows" }, { value: "macos", label: "macOS" }, { value: "linux", label: "Linux" }, ]; const timezoneOptions = [ { value: "America/New_York", label: "America/New_York" }, { value: "America/Los_Angeles", label: "America/Los_Angeles" }, { value: "Europe/London", label: "Europe/London" }, { value: "Europe/Paris", label: "Europe/Paris" }, { value: "Asia/Tokyo", label: "Asia/Tokyo" }, { value: "Asia/Shanghai", label: "Asia/Shanghai" }, { value: "Australia/Sydney", label: "Australia/Sydney" }, ]; const localeOptions = [ { value: "en-US", label: "English (US)" }, { value: "en-GB", label: "English (UK)" }, { value: "fr-FR", label: "French" }, { value: "de-DE", label: "German" }, { value: "es-ES", label: "Spanish" }, { value: "it-IT", label: "Italian" }, { value: "ja-JP", label: "Japanese" }, { value: "zh-CN", label: "Chinese (Simplified)" }, ]; const getCurrentOS = () => { if (typeof window !== "undefined") { const userAgent = window.navigator.userAgent; if (userAgent.includes("Win")) return "windows"; if (userAgent.includes("Mac")) return "macos"; if (userAgent.includes("Linux")) return "linux"; } return "unknown"; }; export function CamoufoxConfigDialog({ isOpen, onClose, profile, onSave, }: CamoufoxConfigDialogProps) { const [config, setConfig] = useState({ enable_cache: true, os: [getCurrentOS()], }); const [isSaving, setIsSaving] = useState(false); // Initialize config when profile changes useEffect(() => { if (profile && profile.browser === "camoufox") { setConfig( profile.camoufox_config || { enable_cache: true, os: [getCurrentOS()], }, ); } }, [profile]); const updateConfig = (key: keyof CamoufoxConfig, value: unknown) => { setConfig((prev) => ({ ...prev, [key]: value })); }; const handleSave = async () => { if (!profile) return; setIsSaving(true); try { await onSave(profile, config); onClose(); } catch (error) { console.error("Failed to save camoufox config:", error); } finally { setIsSaving(false); } }; const handleClose = () => { // Reset config to original when closing without saving if (profile && profile.browser === "camoufox") { setConfig( profile.camoufox_config || { enable_cache: true, os: [getCurrentOS()], }, ); } onClose(); }; if (!profile || profile.browser !== "camoufox") { return null; } // Get the selected OS for warning const selectedOS = config.os?.[0]; const currentOS = getCurrentOS(); const showOSWarning = selectedOS && selectedOS !== currentOS && currentOS !== "unknown"; return ( Configure Camoufox Settings - {profile.name}
{/* Operating System */}
{showOSWarning && (

⚠️ Warning: Spoofing OS features is detectable by advanced anti-bot systems. Some platform-specific APIs and behaviors cannot be fully replicated.

)}
{/* Blocking Options */}
updateConfig("block_images", checked) } />
updateConfig("block_webrtc", checked) } />
updateConfig("block_webgl", checked) } />
{/* Geolocation */}
updateConfig("country", e.target.value || undefined) } placeholder="e.g., US, GB, DE" />
updateConfig( "latitude", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., 40.7128" />
updateConfig( "longitude", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., -74.0060" />
{/* Localization */}
{/* Screen Resolution */}
updateConfig( "screen_min_width", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 1024" />
updateConfig( "screen_max_width", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 1920" />
updateConfig( "screen_min_height", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 768" />
updateConfig( "screen_max_height", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 1080" />
{/* Window Size */}
updateConfig( "window_width", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 1366" />
updateConfig( "window_height", e.target.value ? parseInt(e.target.value) : undefined, ) } placeholder="e.g., 768" />
{/* Advanced Options */}
updateConfig("enable_cache", checked) } />
updateConfig("main_world_eval", checked) } />
{/* WebGL Settings */}
updateConfig("webgl_vendor", e.target.value || undefined) } placeholder="e.g., Intel Inc." />
updateConfig( "webgl_renderer", e.target.value || undefined, ) } placeholder="e.g., Intel Iris OpenGL Engine" />
{/* Debug Options */}
updateConfig("debug", checked)} />
); }