commit a8db094eabb33f8fa57aa075a1e952b82774fd66
parent 441a79a1710b5ae1829251a4d799f67baf2ec396
Author: anon <anon@example.com>
Date: Mon, 19 Oct 2026 20:54:35 +0000
Register viewport listeners after browser controls initialize
Diffstat:
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/browser/index.html b/src/browser/index.html
@@ -166,8 +166,6 @@
}
positionChat();
}
- window.visualViewport?.addEventListener('resize', updateChatViewport);
- window.visualViewport?.addEventListener('scroll', updateChatViewport);
// HTTP handles decompression; count prepared bytes while compilation streams.
async function instantiateClient(imports, receive) {
@@ -719,6 +717,8 @@ show();
document.addEventListener('visibilitychange', () => {
if (document.hidden) releaseControls();
});
+ window.visualViewport?.addEventListener('resize', updateChatViewport);
+ window.visualViewport?.addEventListener('scroll', updateChatViewport);
startGame().catch(error => Module.onAbort(error.message));
</script>
</html>
diff --git a/src/tests/browser_controls.mjs b/src/tests/browser_controls.mjs
@@ -63,8 +63,12 @@ function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.
clearTimeout: id => timers.delete(id)
});
const html = fs.readFileSync(new URL('../browser/index.html', import.meta.url), 'utf8');
- for (const script of html.matchAll(/<script(?: id="player-controls")?>([\s\S]*?)<\/script>/g))
+ for (const script of html.matchAll(/<script(?: id="player-controls")?>([\s\S]*?)<\/script>/g)) {
vm.runInContext(script[1], context);
+ // Viewport events can arrive while the HTML parser waits for the next script.
+ window.visualViewport.dispatchEvent(new Event('resize'));
+ window.visualViewport.dispatchEvent(new Event('scroll'));
+ }
context.Module._browser_input_key = (key, down) => keys.push([key, down]);
context.Module._browser_input_character = character => characters.push(character);
context.Module._browser_input_motion = (x, y) => mouse.push(['mousemove', x, y, 0]);