aboutsummaryrefslogtreecommitdiff
path: root/test-suite/challenges/22-touch-events.html
diff options
context:
space:
mode:
authorTianren Dong <tianrendong.dtr@gmail.com>2026-05-13 01:05:46 -0400
committerTianren Dong <tianrendong.dtr@gmail.com>2026-05-13 01:05:46 -0400
commit33110e803fcacc31dc2859dbc0d470b008556798 (patch)
treebb30dad365139c558f9d9651cb8bca375320cb8e /test-suite/challenges/22-touch-events.html
parentd78081aa58ecaa1c72e847c2d095b5f07c391506 (diff)
pi-chrome: humanize synthetic input + anti-automation test suite
Bump 0.8.0 → 0.9.1. Companion extension (service_worker.js): - humanise pointer paths: easing Bezier-ish interpolation w/ wobble, 12–42 steps, 4–18 ms gaps; pointer position persisted across calls - click point picked inside element rect, not dead center - pointer events fill movementX/Y, screenX/Y, pressure (0.5 on down), pointerId, width/height, tilt, composed - click sequence: humanMoveTo → pointerdown → focus → 45–140 ms hold → pointerup → mouseup → click - per-character typing: keydown → keypress → beforeinput → value mutate (or execCommand for contenteditable) → input → keyup, with 25–95 ms hold + 35–140 ms inter-key; auto Shift chord for uppercase/symbols - pressKeyInPage emits same cadence + handles printable insert / Backspace - hoverPage: humanised path + 80–220 ms dwell - dragPage: full HTML5 sequence (dragstart/drag/dragenter/dragover/ dragleave/drop/dragend) with shared DataTransfer + pointer continuity - new scrollPage: wheel events with front-loaded momentum-shaped deltas - self-reload on version drift: SW reads x-pi-chrome-version header, reloads when older than pi-chrome Pi side (index.ts): - new chrome_scroll tool - PI_CHROME_VERSION read from package.json (and re-read on every /next so future bumps take effect without pi restart) - /chrome-doctor escalates version mismatch to top-line ✗ error and skips downstream capability probes when stale - /next response carries x-pi-chrome-version header for SW self-heal Test suite (test-suite/): - 28 challenge pages each catching a different synthetic-event tell: isTrusted, webdriver/fingerprint, mouse entropy/timing/coords, pointer pressure/continuity, per-char cadence + framework invariants, user activation, honeypots, focus order, wheel scroll, drag+ DataTransfer, contenteditable+Selection, paste/clipboard, native select, hover dwell, React valueTracker, keyboard modifiers, touch events, stack-trace fingerprint, viewport-edge clicks, mousemove rate, scroll momentum, IntersectionObserver visibility - shared _lib.js exposes window.__verdict + writes localStorage so index.html dashboard aggregates results - notes/bypass-ideas.md documents fixes still needed per challenge
Diffstat (limited to 'test-suite/challenges/22-touch-events.html')
-rw-r--r--test-suite/challenges/22-touch-events.html66
1 files changed, 66 insertions, 0 deletions
diff --git a/test-suite/challenges/22-touch-events.html b/test-suite/challenges/22-touch-events.html
new file mode 100644
index 0000000..042ddf4
--- /dev/null
+++ b/test-suite/challenges/22-touch-events.html
@@ -0,0 +1,66 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>22 touch events</title>
+<link rel="stylesheet" href="../_style.css">
+<script src="../_lib.js"></script>
+<body>
+<main>
+ <p>Goal: tap the green pad on a touch-capable device (or via DevTools touch
+ emulation). Page asserts a real <code>touchstart</code>/<code>touchend</code> sequence:
+ <code>touches</code> / <code>changedTouches</code> are
+ <code>TouchList</code> objects containing <code>Touch</code> instances with
+ <code>identifier</code>, <code>clientX/Y</code>, <code>radiusX/Y</code>, and
+ <code>force</code> in [0,1]. Synthetic <code>PointerEvent</code> with
+ <code>pointerType="touch"</code> alone does not satisfy this — touch events must
+ fire too.</p>
+ <p><b>Note for caller:</b> requires Chrome touch emulation on (DevTools → Sensors →
+ "Touch: Force enabled") or a real touchscreen. This is intentional: pi-chrome's
+ synthetic <code>pointerType:'touch'</code> does NOT also dispatch TouchEvents.</p>
+ <div id="pad" style="width:200px;height:200px;background:#1f7a1f;border-radius:12px;color:#fff;display:flex;align-items:center;justify-content:center;font:18px monospace;touch-action:none;user-select:none">
+ TAP
+ </div>
+</main>
+<script>
+Challenge.init({ id: "touch-events", instructions: "tap the pad on a touch-capable device" });
+const pad = document.getElementById("pad");
+
+let touchStart = null, touchEnd = null;
+pad.addEventListener("touchstart", (e) => {
+ touchStart = e;
+ Challenge.log("touchstart", { tl: e.touches.length, ct: e.changedTouches.length, isTrusted: e.isTrusted });
+}, { passive: true });
+pad.addEventListener("touchend", (e) => {
+ touchEnd = e;
+ const bad = [];
+ if (!touchStart) return Challenge.fail("touchend without touchstart");
+ if (!e.isTrusted || !touchStart.isTrusted) bad.push("touch event isTrusted=false");
+
+ const ts = touchStart.changedTouches;
+ if (!ts || ts.length === 0) bad.push("touchstart.changedTouches empty");
+ else {
+ const T = ts[0];
+ // Window.Touch should exist as the constructor.
+ if (typeof window.Touch !== "function") bad.push("window.Touch constructor missing (no native TouchEvent support)");
+ if (!(T instanceof Touch)) bad.push("changedTouches[0] not instanceof Touch");
+ if (typeof T.identifier !== "number") bad.push("Touch.identifier not number");
+ if (!Number.isFinite(T.clientX) || !Number.isFinite(T.clientY)) bad.push("Touch.clientX/Y invalid");
+ if (!("force" in T) || typeof T.force !== "number" || T.force < 0 || T.force > 1) bad.push(`Touch.force=${T.force}`);
+ if (!("radiusX" in T) || typeof T.radiusX !== "number") bad.push("Touch.radiusX missing");
+ }
+
+ if (!(touchStart instanceof TouchEvent)) bad.push("touchstart not instanceof TouchEvent");
+
+ if (bad.length) Challenge.fail(...bad);
+ else Challenge.pass("real TouchEvent + Touch object surface present");
+}, { passive: true });
+
+// Capability check: if TouchEvent constructor missing entirely, hint immediately on click.
+pad.addEventListener("click", () => {
+ if (!touchStart && typeof window.TouchEvent !== "function") {
+ Challenge.fail("TouchEvent constructor not available on this UA (enable touch emulation)");
+ } else if (!touchStart) {
+ Challenge.fail("click fired but no touchstart — synthetic pointer without TouchEvent");
+ }
+});
+</script>
+</body>