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.
This commit is contained in:
Eliott C. 2026-09-27 10:13:16 +02:00 • committed by GitHub
commit 0f1f9b7ccf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

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

View file

@ -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) => {