From 0f1f9b7ccfc303299a0d926caa909399296b1e80 Mon Sep 17 00:00:00 2001 From: "Eliott C." Date: Sun, 27 Sep 2026 10:13:16 +0200 Subject: [PATCH] Allow page scrolling over the game canvas (#510) Swiping over the game canvas prevented the surrounding page from scrolling, making the platform chat difficult to reach on a phone. Allow native vertical scrolling and pinch zoom while retaining browser-generated mouse events for taps. Plain wheel gestures scroll the page; Ctrl/Command-wheel and fullscreen retain board zoom. The change intercepts only the canvas library's blanket touch/wheel cancellation. Validation against the built published-compatible WASM viewer: native touch and wheel scrolling, no move emitted during a swipe, and one mouse press/release pair per tap. --- client/js/src/page-scrolling.js | 16 ++++++++++++++++ client/js/src/run.js | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 client/js/src/page-scrolling.js diff --git a/client/js/src/page-scrolling.js b/client/js/src/page-scrolling.js new file mode 100644 index 00000000..7e17df59 --- /dev/null +++ b/client/js/src/page-scrolling.js @@ -0,0 +1,16 @@ +export function bindPageScrolling(canvas) { + // Miniquad cancels every touch, including swipes meant for the surrounding BGS page. + // Let the browser scroll and generate compatibility mouse events for taps instead. + const nativeTouch = (event) => event.stopImmediatePropagation(); + for (const type of ["touchstart", "touchmove", "touchend", "touchcancel"]) + canvas.addEventListener(type, nativeTouch, { capture: true, passive: true }); + canvas.style.touchAction = "pan-y pinch-zoom"; + canvas.addEventListener( + "wheel", + (event) => { + if (!event.ctrlKey && !event.metaKey && !document.fullscreenElement) + event.stopImmediatePropagation(); + }, + { capture: true, passive: true }, + ); +} diff --git a/client/js/src/run.js b/client/js/src/run.js index 75e1cff1..deb6c2b1 100644 --- a/client/js/src/run.js +++ b/client/js/src/run.js @@ -1,3 +1,4 @@ +import { bindPageScrolling } from "./page-scrolling"; import init, { set_wasm } from "../../dist/remote_client"; function dynamicallyLoadScript(url, onload) { @@ -9,6 +10,7 @@ function dynamicallyLoadScript(url, onload) { } export async function run({ selector, control }) { + bindPageScrolling(document.querySelector(selector)); let wbg = await init(); miniquad_add_plugin({ register_plugin: (a) => {