logi-gamepad-bridge
v0.1.2
Published
Bridge browser Gamepad API haptics to HapticWebPlugin (MX Master 4)
Downloads
418
Readme
logi-gamepad-bridge
Bridge the browser Gamepad Haptics API (GamepadHapticActuator) to HapticWebPlugin on Logitech MX Master 4.
Prerequisites
- Install HapticWebPlugin (Logi Options+ + MX Master 4).
- Ensure
local.jmw.nzresolves to127.0.0.1. - Grant local network access in the browser when prompted.
Browser injection
Paste in the DevTools Console on any tab (patches navigator.getGamepads()):
document.head.appendChild(Object.assign(document.createElement('script'),{src:'https://unpkg.com/[email protected]/dist/inject.min.js'}))A 404 plus nosniff in the console means the CDN returned an HTML error page (often 0.1.0, which has no inject bundle). Hard-refresh or pin the version above.
When you see Gamepad API patched, pick Logitech MX Master 4 (HapticWeb Bridge) if the site lists gamepads, then use its vibration/rumble controls. If it does not show up, refresh and run the line again before the page reads gamepads.
Install (npm)
npm install logi-gamepad-bridgeTest UI
git clone https://github.com/humbertogontijo/logi-gamepad-bridge.git
cd logi-gamepad-bridge
npm install
npm run devOpens http://localhost:5173 — click Connect (HapticWebPlugin must be running).
Build
npm install
npm run buildProduces dist/index.js (library) and dist/inject.min.js (browser injection bundle).
Usage
import { connectLogiGamepad } from 'logi-gamepad-bridge';
const bridge = connectLogiGamepad({
patchGetGamepads: true,
});
window.addEventListener('gamepadconnected', (e) => {
const actuator = e.gamepad.vibrationActuator;
if (!actuator) return;
void actuator.playEffect('dual-rumble', {
duration: 300,
strongMagnitude: 0.9,
weakMagnitude: 0.4,
});
});Direct actuator
import { LogiGamepadBridge } from 'logi-gamepad-bridge';
const bridge = new LogiGamepadBridge();
bridge.connect();
void bridge.actuator.pulse(0.8, 200);How it works
| Gamepad API | Bridge | HapticWebPlugin |
| ----------------------------------- | --------------------------------------------- | ------------------------------ |
| playEffect('dual-rumble', params) | Maps magnitude/duration → waveform index 0–14 | ws.send(Uint8Array([index])) |
| pulse(value, duration) | Same mapper | WebSocket |
| reset() | Clears pending delayed effects | — |
The MX Master 4 only supports 15 fixed waveforms, not continuous rumble. Intensity is capped by Logi Options+ haptic strength.
API
LogiGamepadBridge— WebSocket client + actuator + optional syntheticGamepadLogiHapticActuator—GamepadHapticActuatorimplementationHapticWebClient— low-level HapticWeb WebSocket clientmapEffectToWaveformIndex/mapPulseToWaveformIndexconnectLogiGamepad()/getLogiGamepadBridge()
License
MIT
