Spaces:
Sleeping
Sleeping
File size: 1,920 Bytes
0f5ca68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import React, { useState } from 'react';
const BrowserView = () => {
const [url, setUrl] = useState('');
const [iframeUrl, setIframeUrl] = useState('');
const handleUrlChange = (e) => {
setUrl(e.target.value);
};
const handleLoadUrl = () => {
const trimmed = url.trim();
if (!trimmed) return;
if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) {
setIframeUrl(trimmed);
} else {
setIframeUrl('https://' + trimmed);
}
};
const handleKeyDown = (e) => {
if (e.key === 'Enter') handleLoadUrl();
};
return (
<div className="p-4 bg-black rounded-lg text-white">
<h2 className="text-2xl font-bold mb-4">Browser</h2>
<div className="flex space-x-2 mb-4">
<input
type="text"
value={url}
onChange={handleUrlChange}
onKeyDown={handleKeyDown}
placeholder="Enter a URL"
className="w-full p-2 bg-black border border-white rounded-md text-white focus:ring-invader-pink focus:border-invader-pink"
aria-label="URL to load in embedded browser"
/>
<button
type="button"
onClick={handleLoadUrl}
className="px-4 py-2 bg-invader-pink text-black rounded-md hover:bg-invader-green focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-invader-pink"
>
Load
</button>
</div>
{iframeUrl && (
<>
<p className="text-xs text-white/60 mb-2">
Some sites block embedding (X-Frame-Options). If the page is blank, try another URL.
</p>
<iframe
src={iframeUrl}
className="w-full h-96 rounded-md border border-white"
title="Embedded browser"
sandbox="allow-scripts allow-same-origin allow-forms allow-popups"
/>
</>
)}
</div>
);
};
export default BrowserView;
|