web: shared modal focus controller (M1/M2) — work in progress

This commit is contained in:
2026-10-19 20:46:15 +01:00
parent a7991077d2
commit b1e9400d6e
11 changed files with 1562 additions and 121 deletions
+25
View File
@@ -285,6 +285,31 @@ export async function launchChrome({ width = 1440, height = 900, chromePath } =
{ timeout, what: `text ${JSON.stringify(text)}` },
);
},
/**
* Dispatch one real key event pair (Input.dispatchKeyEvent), so the page
* sees the same trusted Tab/Escape/Enter a keyboard operator produces.
*/
async pressKey(key, { shift = false } = {}) {
const keys = {
Tab: { code: "Tab", windowsVirtualKeyCode: 9 },
Escape: { code: "Escape", windowsVirtualKeyCode: 27 },
Enter: { code: "Enter", windowsVirtualKeyCode: 13, text: "\r", unmodifiedText: "\r" },
" ": { code: "Space", windowsVirtualKeyCode: 32, text: " ", unmodifiedText: " " },
ArrowDown: { code: "ArrowDown", windowsVirtualKeyCode: 40 },
ArrowUp: { code: "ArrowUp", windowsVirtualKeyCode: 38 },
};
const info = keys[key] ?? { code: key, windowsVirtualKeyCode: 0 };
const base = {
key,
code: info.code,
windowsVirtualKeyCode: info.windowsVirtualKeyCode,
nativeVirtualKeyCode: info.windowsVirtualKeyCode,
modifiers: shift ? 8 : 0,
...(info.text ? { text: info.text, unmodifiedText: info.unmodifiedText } : {}),
};
await session("Input.dispatchKeyEvent", { type: "keyDown", ...base });
await session("Input.dispatchKeyEvent", { type: "keyUp", ...base });
},
async text() {
return api.evaluate("document.body.innerText");
},