demo · v143
Multi-controller router
A real local-multiplayer router built around the new window.ongamepadconnected handler attribute (the ergonomic counterpart of addEventListener("gamepadconnected", …)). Plug in up to four pads — each gets a player slot, with axes, buttons, and identity tag live. Unplug and the slot frees instantly.
The handler-attribute form is what you want for code like local co-op games: a single property to write the central dispatcher to, just like onload or onerror.
Player slots
Connection log
What this uses
window.ongamepadconnected— new in v143 as a handler attribute (the event itself shipped years ago).navigator.getGamepads()— polled insiderequestAnimationFrameto read the axes and button state each frame.gamepad.vibrationActuator.playEffect()— to send rumble (if supported).- Slots are tracked by
gamepad.index— Chrome holds them stable across reconnects in the same session.
// v143 idiomatic form
window.ongamepadconnected = (e) => slots[e.gamepad.index] = e.gamepad;
window.ongamepaddisconnected = (e) => delete slots[e.gamepad.index];