fix(web-runtime): drop swipe, restrict pressKey to browser-meaningful keys

Web has no swipe gesture, so swipes dispatched pointer events into empty
divs. Make swipe() and the swipes builtin no-op. For PressKey, replace
the always-"back" choice with a random pick from {enter, tab, escape,
up, down, left, right} - keys that have real semantics in a browser.
This commit is contained in:
pj committed 2026-04-27 20:45:54 +07:00
1 parent 82cf889e16
commit 9c42744c00
1 file changed
+14 -21
+14 -21
View File
@@ -308,8 +308,9 @@ const runtime = {
inputText(p: { into: unknown; text: string }): unknown { inputText(p: { into: unknown; text: string }): unknown {
return { kind: "InputText", into: p.into, text: p.text }; return { kind: "InputText", into: p.into, text: p.text };
}, },
swipe(p: { from: unknown; to: unknown; durationMillis?: number }): unknown { swipe(_p: { from: unknown; to: unknown; durationMillis?: number }): unknown {
return { kind: "Swipe", from: p.from, to: p.to, durationMillis: p.durationMillis }; // Why: web has no swipe gesture; the factory returns null so Swipe() calls in specs no-op.
return null;
}, },
pressKey(p: { key: string }): unknown { pressKey(p: { key: string }): unknown {
return { kind: "PressKey", key: p.key }; return { kind: "PressKey", key: p.key };
@@ -392,7 +393,7 @@ function resolveGenerator(handle: ActionGeneratorHandle): unknown {
case "waitOnce": case "waitOnce":
return { kind: "Wait", durationMillis: 500 }; return { kind: "Wait", durationMillis: 500 };
case "pressKey": case "pressKey":
return { kind: "PressKey", key: "back" }; return randomPressKey();
default: default:
return null; return null;
} }
@@ -422,24 +423,16 @@ function randomTap(): unknown {
} }
function randomSwipe(): unknown { function randomSwipe(): unknown {
const width = window.innerWidth || 320; // Why: web has no swipe gesture; pointer drags into empty divs are noise.
const height = window.innerHeight || 480; return null;
const cx = Math.round(width / 2); }
const cy = Math.round(height / 2);
const magnitude = 200 + Math.floor(Math.random() * 401); const WEB_PRESS_KEYS = ["enter", "tab", "escape", "up", "down", "left", "right"];
const direction = Math.floor(Math.random() * 4);
let toX = cx; function randomPressKey(): unknown {
let toY = cy; // Why: only emit keys with meaningful browser semantics; "back"/"home" don't navigate.
if (direction === 0) toY = Math.max(0, cy - magnitude); const key = WEB_PRESS_KEYS[Math.floor(Math.random() * WEB_PRESS_KEYS.length)];
else if (direction === 1) toY = cy + magnitude; return { kind: "PressKey", key };
else if (direction === 2) toX = Math.max(0, cx - magnitude);
else toX = cx + magnitude;
return {
kind: "Swipe",
from: { x: cx, y: cy },
to: { x: toX, y: toY },
durationMillis: 250,
};
} }
function pickFromArray(value: unknown): unknown { function pickFromArray(value: unknown): unknown {