"use client"; import { useState, useRef } from "react"; import { Globe, RefreshCw, ChevronLeft, ChevronRight, ExternalLink, Smartphone, Monitor } from "lucide-react"; export default function BrowserPanel() { const [url, setUrl] = useState("http://localhost:3000"); const [inputUrl, setInputUrl] = useState("http://localhost:3000"); const [mode, setMode] = useState<"desktop" | "mobile">("desktop"); const iframeRef = useRef(null); const reload = () => { if (iframeRef.current) { iframeRef.current.src = iframeRef.current.src; } }; const navigate = (e: React.FormEvent) => { e.preventDefault(); let target = inputUrl; if (!target.startsWith("http://") && !target.startsWith("https://")) { target = "http://" + target; } setUrl(target); setInputUrl(target); }; // Listen to iframe load events to update URL if possible (though restricted by same-origin policy) const onLoad = () => { try { if (iframeRef.current?.contentWindow?.location.href) { const currentUrl = iframeRef.current.contentWindow.location.href; if (currentUrl !== "about:blank") { setUrl(currentUrl); setInputUrl(currentUrl); } } } catch { // Cross-origin access blocked, ignore } }; return (
{/* Header bar */}
setInputUrl(e.target.value)} />
{/* Browser viewport container */}