xs / static /index.html
ezzygame's picture
Upload static/index.html
6629f45 verified
Raw History Blame Contribute Delete
5.07 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cloud Browser</title>
<style>
:root{color-scheme:dark;font:15px system-ui,sans-serif;background:#101319;color:#edf0f7}
*{box-sizing:border-box}body{margin:0;min-height:100vh;display:flex;flex-direction:column}
header{padding:12px 16px;background:#191e28;border-bottom:1px solid #303746;display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.brand{font-weight:700;margin-right:10px}.address{display:flex;gap:8px;flex:1;min-width:240px}
input{background:#0d1118;border:1px solid #3b4352;border-radius:9px;color:#fff;padding:10px 12px;min-width:0;flex:1}
button{border:1px solid #414a5b;background:#272e3b;color:#fff;border-radius:9px;padding:9px 12px;cursor:pointer}
button:hover{background:#353e4f}button:disabled{opacity:.5;cursor:wait}
main{padding:14px;display:flex;flex-direction:column;gap:10px;flex:1}
#status{color:#aeb9cc;font-size:13px;min-height:18px}
#viewport{background:#080a0e;border:1px solid #303746;border-radius:12px;overflow:auto;display:flex;align-items:flex-start;justify-content:center;min-height:300px;flex:1}
#screen{display:block;width:100%;height:auto;cursor:crosshair;outline:none;image-rendering:auto}
.hint{color:#8d98aa;font-size:12px}
@media(min-width:1000px){main{padding:20px}#viewport{min-height:calc(100vh - 150px)}}
</style>
</head>
<body>
<header>
<span class="brand">☁ Cloud Browser</span>
<button id="back" title="Back">←</button><button id="forward" title="Forward">→</button><button id="reload" title="Reload">⟳</button>
<form class="address" id="navform"><input id="url" value="https://example.com" aria-label="Website URL"><button type="submit">Go</button></form>
</header>
<main>
<div id="status">Enter the access key to start a private browser session.</div>
<div id="viewport"><img id="screen" alt="Remote Chromium screen" tabindex="0"></div>
<div class="hint">Click the page to focus it. Typing and scrolling are sent to the remote browser. This prototype does not support audio or downloads.</div>
</main>
<script>
let sessionId=null, ws=null, naturalW=1280, naturalH=800;
const $=id=>document.getElementById(id), status=$('status');
async function api(path,body,method='POST'){
const r=await fetch(path,{method,headers:{'Content-Type':'application/json'},body:body?JSON.stringify(body):undefined});
const d=await r.json(); if(!r.ok)throw Error(d.detail||'Request failed'); return d;
}
async function start(){
const key=prompt('Access key');
if(!key)return;
try{
status.textContent='Starting isolated Chromium session…';
const d=await api('/api/session',{access_key:key});sessionId=d.session_id;
$('url').value=d.url;status.textContent='Connected · '+d.title;
ws=new WebSocket(`${location.protocol==='https:'?'wss':'ws'}://${location.host}/ws/${sessionId}`);
ws.binaryType='blob';
ws.onmessage=e=>{const img=$('screen');const old=img.dataset.blob;if(old)URL.revokeObjectURL(old);const u=URL.createObjectURL(e.data);img.dataset.blob=u;img.src=u;};
ws.onclose=()=>{status.textContent='Stream disconnected. Reload to start a new session.'};
}catch(e){status.textContent=e.message}
}
async function navigate(raw){
if(!sessionId) return;
let value=raw.trim();if(!/^https?:\/\//i.test(value))value='https://'+value;
try{status.textContent='Loading…';const d=await api('/api/navigate',{session_id:sessionId,url:value});$('url').value=d.url;status.textContent=d.title+' · '+d.url;}
catch(e){status.textContent=e.message}
}
$('navform').addEventListener('submit',e=>{e.preventDefault();navigate($('url').value)});
async function action(a,extra={}){if(!sessionId)return;try{const d=await api('/api/action',{session_id:sessionId,action:a,...extra});if(d.url)$('url').value=d.url;status.textContent=d.title+' · '+d.url;}catch(e){status.textContent=e.message}}
$('back').onclick=()=>action('back');$('forward').onclick=()=>action('forward');$('reload').onclick=()=>action('reload');
const screen=$('screen');
screen.addEventListener('click',e=>{
const r=screen.getBoundingClientRect();
const x=(e.clientX-r.left)*naturalW/r.width, y=(e.clientY-r.top)*naturalH/r.height;
action('click',{x,y});screen.focus();
});
screen.addEventListener('keydown',e=>{
if(e.key.length===1&&!e.ctrlKey&&!e.metaKey){e.preventDefault();action('type',{text:e.key});}
else {const map={Enter:'Enter',Escape:'Escape',Backspace:'Backspace',Tab:'Tab',ArrowUp:'ArrowUp',ArrowDown:'ArrowDown',ArrowLeft:'ArrowLeft',ArrowRight:'ArrowRight',Home:'Home',End:'End',PageUp:'PageUp',PageDown:'PageDown'};
if(map[e.key]){e.preventDefault();action('key',{text:map[e.key]});}
else if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='a'){e.preventDefault();action('key',{text:'Control+A'});}
}
});
$('viewport').addEventListener('wheel',e=>{e.preventDefault();action('scroll',{delta_y:Math.round(e.deltaY)});},{passive:false});
window.addEventListener('beforeunload',()=>{if(sessionId)navigator.sendBeacon(`/api/session/${sessionId}`);});
start();
</script>
</body>
</html>