Watch
0
0
Fork
You've already forked hyperhive
0

agent: let the screen page keep reload, the address bar and its own buttons

The page forwarded every key to the remote desktop and cancelled it, so F5 and
Ctrl+R could not reload, though the disconnect message tells the operator to
reload, and Enter or Space on the fit and debug buttons did nothing. F5, F12,
Ctrl/Cmd+R, Ctrl/Cmd+L and any key pressed on a button now go to the browser;
the rest still go to the remote desktop. The filter is a small module with a
test, bundled for the page as static/screen-keys.js, and the agent-page doc
describes it.
This commit is contained in:
iris 2026-11-25 19:24:08 +01:00
commit ff7215a4b1
6 changed files with 80 additions and 0 deletions

View file

@ -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:<vnc_port>`.
Transparent to any RFB variant. VNC port comes from the

View file

@ -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(""));

View file

@ -6,6 +6,7 @@
"type": "module",
"scripts": {
"build": "node ./build.mjs",
"test": "node --test test/*.test.mjs",
"typecheck": "tsc --noEmit"
},
"dependencies": {

View file

@ -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);
}

View file

@ -32,6 +32,7 @@
<div id="msg"></div>
<div id="debug-log"></div>
<script src="static/screen-keys.js"></script>
<script>
// Minimal RFB-over-WebSocket renderer. Connects to `screen/ws` on
// the same host; the harness relays raw RFB bytes to the VNC server
@ -942,6 +943,9 @@
document.addEventListener("keyup", (ev) => sendKey(ev, 0));
function sendKey(ev, down) {
// Reload, the address bar, the dev tools and the page's own buttons
// keep their keys (src/screen-keys.js).
if (hiveScreenKeys.keepForBrowser(ev)) return;
ev.preventDefault();
const key = rfbKeysym(ev);
const b = new Uint8Array(8);

View file

@ -0,0 +1,40 @@
// Which keys the screen page leaves to the browser. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { keepForBrowser } from "../src/screen-keys.js";
const plain = { closest: () => null };
const button = { closest: (sel) => (sel === "button" ? {} : null) };
test("reload, the address bar and the dev tools stay with the browser", () => {
assert.equal(keepForBrowser({ key: "F5", target: plain }), true);
assert.equal(keepForBrowser({ key: "F12", target: plain }), true);
assert.equal(
keepForBrowser({ key: "r", ctrlKey: true, target: plain }),
true,
);
assert.equal(
keepForBrowser({ key: "R", metaKey: true, target: plain }),
true,
);
assert.equal(
keepForBrowser({ key: "l", ctrlKey: true, target: plain }),
true,
);
});
test("a key pressed on a button stays with the button", () => {
assert.equal(keepForBrowser({ key: "Enter", target: button }), true);
assert.equal(keepForBrowser({ key: " ", target: button }), true);
});
test("everything else goes to the remote desktop", () => {
assert.equal(keepForBrowser({ key: "a", target: plain }), false);
assert.equal(keepForBrowser({ key: "r", target: plain }), false);
assert.equal(
keepForBrowser({ key: "c", ctrlKey: true, target: plain }),
false,
);
assert.equal(keepForBrowser({ key: "F4", target: plain }), false);
assert.equal(keepForBrowser({ key: "Enter" }), false);
});