diff --git a/docs/4-implementation/web-ui/agent-page.md b/docs/4-implementation/web-ui/agent-page.md index 966d1e7f8..a363cc780 100644 --- a/docs/4-implementation/web-ui/agent-page.md +++ b/docs/4-implementation/web-ui/agent-page.md @@ -47,6 +47,12 @@ credentials arrive from the swarm secret store. Fit-mode state persists in `localStorage` (`screen-fit`); default is on. `sendPointer` rescales pointer coordinates so presses land on the right pixel regardless of CSS scale. + Keyboard events go to the remote desktop and the page cancels them, + except the keys the browser keeps: F5 and F12, Ctrl or Cmd with R or L, + and any key pressed while one of the page's buttons has focus. That filter + is `keepForBrowser` in `src/screen-keys.js`, loaded by the page as + `static/screen-keys.js`, so the viewer can still reload and its buttons + work from the keyboard. - `GET /screen/ws` — raw RFB byte relay: proxies WebSocket frames to the weston VNC server at `127.0.0.1:`. Transparent to any RFB variant. VNC port comes from the diff --git a/frontend/packages/agent/build.mjs b/frontend/packages/agent/build.mjs index db1448475..36611434c 100644 --- a/frontend/packages/agent/build.mjs +++ b/frontend/packages/agent/build.mjs @@ -3,6 +3,7 @@ // dist/screen.html served at GET /screen // dist/static/agent.css served at /static/agent.css (@import // resolved from @hive/shared) +// dist/static/screen-keys.js the key filter `screen.html` loads // // The in-container Rust binary mounts `dist/` (with per-agent // `services.hyperhive.agent.frontend.extraFiles` layered on top) as a @@ -37,6 +38,17 @@ for (const entry of ["colors.css", "theme.css", "agent.css"]) { }); } +// The key filter the screen page loads ahead of its own script, as the global +// `hiveScreenKeys` (the page's script is classic, not a module). +await build({ + entryPoints: [src("screen-keys.js")], + outfile: staticDir("screen-keys.js"), + bundle: true, + format: "iife", + globalName: "hiveScreenKeys", + logLevel: "info", +}); + copyFileSync(src("screen.html"), dist("screen.html")); console.log("agent build ok →", dist("")); diff --git a/frontend/packages/agent/package.json b/frontend/packages/agent/package.json index 8b1819dee..705837e50 100644 --- a/frontend/packages/agent/package.json +++ b/frontend/packages/agent/package.json @@ -6,6 +6,7 @@ "type": "module", "scripts": { "build": "node ./build.mjs", + "test": "node --test test/*.test.mjs", "typecheck": "tsc --noEmit" }, "dependencies": { diff --git a/frontend/packages/agent/src/screen-keys.js b/frontend/packages/agent/src/screen-keys.js new file mode 100644 index 000000000..133550265 --- /dev/null +++ b/frontend/packages/agent/src/screen-keys.js @@ -0,0 +1,17 @@ +// Which key events the screen page leaves to the browser instead of sending to +// the remote desktop. Kept apart from `screen.html` so a test can load it; +// `build.mjs` bundles it as `static/screen-keys.js`, which the page loads ahead +// of its own script as `hiveScreenKeys`. + +/** + * Keys that belong to the browser or to the page's own buttons: reload (F5, + * Ctrl/Cmd+R), the address bar (Ctrl/Cmd+L), the dev tools (F12), and any key + * pressed while a button has focus (so Enter and Space can click it). + * + * @param {{ key: string, ctrlKey?: boolean, metaKey?: boolean, target?: any }} ev + */ +export function keepForBrowser(ev) { + if (ev.target?.closest?.("button")) return true; + if (ev.key === "F5" || ev.key === "F12") return true; + return Boolean(ev.ctrlKey || ev.metaKey) && /^[rl]$/i.test(ev.key); +} diff --git a/frontend/packages/agent/src/screen.html b/frontend/packages/agent/src/screen.html index 8e6827eca..7e59b2811 100644 --- a/frontend/packages/agent/src/screen.html +++ b/frontend/packages/agent/src/screen.html @@ -32,6 +32,7 @@
+