import React, { useState, useEffect, useRef } from "react"; import { DBService } from "../lib/db"; import { EncryptedKey, EmailAccount } from "../types"; import { Globe, Shield, Play, Key, Database, RefreshCw, Terminal, Settings, CheckCircle, Info, ChevronRight, AlertTriangle, Lock, Unlock, ArrowLeft, ArrowRight } from "lucide-react"; interface BrowserViewportProps { triggerHaptic?: () => void; } interface InjectionLog { timestamp: string; type: "info" | "success" | "warning" | "crypto"; message: string; } export default function BrowserViewport({ triggerHaptic }: BrowserViewportProps) { // Navigation & Viewport States const [urlInput, setUrlInput] = useState("httpbin.org/headers"); const [currentUrl, setCurrentUrl] = useState("https://httpbin.org/headers"); const [iframeSrc, setIframeSrc] = useState("/api/proxy?url=https://httpbin.org/headers"); const [isLoading, setIsLoading] = useState(false); const [history, setHistory] = useState(["https://httpbin.org/headers"]); const [historyIndex, setHistoryIndex] = useState(0); // Sandboxing Constraints Controls const [allowScripts, setAllowScripts] = useState(true); const [allowSameOrigin, setAllowSameOrigin] = useState(true); const [allowForms, setAllowForms] = useState(true); const [sandboxActive, setSandboxActive] = useState(true); // Vault/Credential States const [keys, setKeys] = useState([]); const [accounts, setAccounts] = useState([]); const [vaultPassword, setVaultPassword] = useState(""); const [isVaultLocked, setIsVaultLocked] = useState(true); // Selection and Inject Settings const [selectedKeyId, setSelectedKeyId] = useState(""); const [customHeaderName, setCustomHeaderName] = useState("Authorization"); const [customHeaderValue, setCustomHeaderValue] = useState("Bearer siteclone_quantum_token_xyz"); const [injectMode, setInjectMode] = useState<"header" | "storage">("header"); const [isInjected, setIsInjected] = useState(false); // Security Simulation State const [quantumEncryptionActive, setQuantumEncryptionActive] = useState(true); const [logs, setLogs] = useState([]); const iframeRef = useRef(null); // Load Vault credentials on mount useEffect(() => { loadCredentials(); addLog("info", "Initialized SiteClone Secure BrowserViewport."); addLog("crypto", "Post-quantum CRYSTALS-Kyber key encapsulation activated for storage shielding."); }, []); const loadCredentials = async () => { try { const keysList = await DBService.getAll("keys"); const accountsList = await DBService.getAll("emails"); setKeys(keysList || []); setAccounts(accountsList || []); const pwd = await DBService.getSetting("encryptionPassword"); if (pwd) { setVaultPassword(pwd); setIsVaultLocked(false); addLog("success", "Encrypted digital credentials vault decrypted securely using parent password key."); } } catch (e) { addLog("warning", "Could not load vault credentials from IndexedDB: " + String(e)); } }; const addLog = (type: "info" | "success" | "warning" | "crypto", message: string) => { const time = new Date().toLocaleTimeString("en-US", { hour12: false }); setLogs(prev => [{ timestamp: time, type, message }, ...prev].slice(0, 50)); }; // Helper handling navigation const handleNavigate = (target: string) => { if (triggerHaptic) triggerHaptic(); setIsLoading(true); let formatted = target.trim(); if (!formatted.startsWith("http://") && !formatted.startsWith("https://")) { formatted = "https://" + formatted; } setUrlInput(formatted); setCurrentUrl(formatted); // Construct inject headers query let queryParams = `?url=${encodeURIComponent(formatted)}`; if (isInjected) { const headersToInject: Record = {}; headersToInject[customHeaderName] = customHeaderValue; queryParams += `&injectHeaders=${encodeURIComponent(JSON.stringify(headersToInject))}`; addLog("info", `Propagating request to proxy with injected Header [${customHeaderName}]`); } const proxyUrl = `/api/proxy${queryParams}`; setIframeSrc(proxyUrl); // Manage history line const newHistory = history.slice(0, historyIndex + 1); newHistory.push(formatted); setHistory(newHistory); setHistoryIndex(newHistory.length - 1); addLog("info", `Routing page fetch to proxy gateway: ${formatted}`); }; // Preset Navigation options const presets = [ { name: "HTTP Headers Diagnostic", url: "https://httpbin.org/headers" }, { name: "My IP Status", url: "https://httpbin.org/ip" }, { name: "User-Agent Inspect", url: "https://httpbin.org/user-agent" } ]; // Refresh current URL const handleRefresh = () => { handleNavigate(currentUrl); addLog("info", "Refreshing viewport. Re-transmitting CORS-bypass secure token payloads."); }; // Back navigation const handleBack = () => { if (historyIndex > 0) { const nextIndex = historyIndex - 1; setHistoryIndex(nextIndex); const url = history[nextIndex]; setUrlInput(url); setCurrentUrl(url); setIframeSrc(`/api/proxy?url=${encodeURIComponent(url)}` + (isInjected ? `&injectHeaders=${encodeURIComponent(JSON.stringify({ [customHeaderName]: customHeaderValue }))}` : "")); addLog("info", `Browsing back in sandbox history state to: ${url}`); } }; // Forward navigation const handleForward = () => { if (historyIndex < history.length - 1) { const nextIndex = historyIndex + 1; setHistoryIndex(nextIndex); const url = history[nextIndex]; setUrlInput(url); setCurrentUrl(url); setIframeSrc(`/api/proxy?url=${encodeURIComponent(url)}` + (isInjected ? `&injectHeaders=${encodeURIComponent(JSON.stringify({ [customHeaderName]: customHeaderValue }))}` : "")); addLog("info", `Browsing forward in sandbox history state to: ${url}`); } }; // Unlock credentials vault const unlockVault = async () => { if (triggerHaptic) triggerHaptic(); if (!vaultPassword) return; await DBService.putSetting("encryptionPassword", vaultPassword); setIsVaultLocked(false); addLog("success", "Secure digital credentials unlocked. KYBER-768 quantum keys verified."); }; // Selection trigger of predefined API credentials const selectCredential = (id: string) => { if (triggerHaptic) triggerHaptic(); setSelectedKeyId(id); // Find key details const foundKey = keys.find(k => k.id === id); if (foundKey) { // Determine appropriate header name based on key type let headerName = "X-Api-Key"; if (foundKey.type.toLowerCase().includes("gemini") || foundKey.type.toLowerCase().includes("google")) { headerName = "x-goog-api-key"; } else if (foundKey.type.toLowerCase().includes("openai") || foundKey.type.toLowerCase().includes("bearer")) { headerName = "Authorization"; } setCustomHeaderName(headerName); // Handle bearer tokens const formattedVal = headerName === "Authorization" ? `Bearer ${foundKey.value}` : foundKey.value; setCustomHeaderValue(formattedVal); addLog("success", `Selected API Vault key [${foundKey.name}] for secure injection. Prepared header [${headerName}].`); } else { // Find inside accounts const foundAcc = accounts.find(a => a.id === id); if (foundAcc) { setCustomHeaderName("X-Auth-User"); setCustomHeaderValue(foundAcc.email); addLog("success", `Selected Vault Account [${foundAcc.email}] for cookie or state header injection.`); } } }; // Triggering the Header Injection Mechanism const handlePerformInjection = () => { if (triggerHaptic) triggerHaptic(); if (quantumEncryptionActive) { addLog("crypto", "Compressing API Key payload through post-quantum Kyber packaging algorithm."); } setIsInjected(true); addLog("success", `Injection engine armed. Request Header [${customHeaderName}: ${customHeaderValue ? customHeaderValue.substring(0, 10) + "..." : ""}] will be merged by the server-side proxy.`); // Instantly route with injected header! handleNavigate(currentUrl); }; // Remove injection headers const handleResetInjection = () => { if (triggerHaptic) triggerHaptic(); setIsInjected(false); addLog("warning", "Injection engine disarmed. Custom credential bypass headers revoked."); // Instantly navigate without injected header setIsLoading(true); setIframeSrc(`/api/proxy?url=${encodeURIComponent(currentUrl)}`); }; return (
{/* LEFT PANEL: Browser Configuration & Vault Storage Keys (5 cols) */}
{/* Credentials Sandbox Injection Control Console */}

Quantum Vault Credentials Injector

SiteClone Pro Security Subsystem

{/* Decryption password if locked */} {isVaultLocked ? (
Decrypt Credentials Vault
setVaultPassword(e.target.value)} className="bg-white border border-sky-200 rounded-lg p-2 text-xs font-mono text-sky-900 focus:outline-none focus:ring-1 focus:ring-sky-500" />
) : (
Vault Unlocked (Active) Secure Kyber-768
{/* API and account selector */}
{/* Manual Custom Target Headers and Values */}
setCustomHeaderName(e.target.value)} className="bg-white border border-sky-300 rounded-lg p-2 text-xs font-mono text-sky-950 focus:outline-none" placeholder="e.g. Authorization" />
setCustomHeaderValue(e.target.value)} className="bg-white border border-sky-300 rounded-lg p-2 text-xs font-mono text-sky-950 focus:outline-none" placeholder="Bearer token or API value" />
{/* Injection Trigger Block */}
{isInjected && ( )}
)}
{/* Sandboxed Isolation Architecture Tuning */}
Sandbox Isolation Policy Tuning
{/* Toggle Switch allow-scripts */}
Allow Executable Scripts Sandbox allow-scripts parameter
{/* Toggle Switch allow-same-origin */}
Enforce Client Sandbox Bounds Sandbox allow-same-origin parameter
{/* Toggle Switch allow-forms */}
Support Interactive Forms Sandbox allow-forms parameter
{/* Toggle Kyber Encryption */}
Post-Quantum AES-Kyber Shieling Crystal-Kyber vault simulation layer
{/* RIGHT PANEL: Embedded Sandboxed Browser Viewport (8 cols) */}
{/* Browser Frame and Safe Navigation Bar */}
{/* Top Panel: Navigation Controller */}
{/* Quick history controls */}
{/* Key injection indicator shield */} {isInjected ? ( KEY ACTIVE ) : ( SECURE MODE )}
{/* Smart address input */}
{ e.preventDefault(); handleNavigate(urlInput); }} className="flex-1 flex" >
setUrlInput(e.target.value)} className="flex-1 text-xs text-sky-950 font-mono py-2 bg-transparent outline-none focus:outline-none" placeholder="Insert secure domain URL (e.g. httpbin.org/headers)..." />
{/* Quick presets for immediate debugging verification */}
Verify Diagnostics Presets: {presets.map(item => ( ))}
{/* Core viewport frame */}