Bypass interaction requirement for navigator.getGamepads in Electron

50 views Asked by At

I use electron for a robotics application, in which we have a custom joystick controller. This joystick has several buttons and knobs that have states that we show in our application (such as a speed dial 0-100%).

For security (fingerprinting) reasons, the Gamepad API does not show a gamepad as connected until the user interacts with it.

enter image description here

This however causes an issue with displaying the state of these buttons at startup. As a product where we control the users computer, the electron app and the joystick programming, this is not a security concern.

Are there any additional flags that I can set to ignore this behavior and see all gamepads on startup, regardless of if a user has pressed a button? Or has electron built a way to bypass this? I'm not having any luck finding anything.

My other option is to change our USB joystick code to just toggle a random button we don't use, to simulate it being pressed but this feels hacky.

1

There are 1 answers

0
nondebug On

This is not possible with Gamepad API. The gamepad user gesture requirement is part of the Gamepad API specification and is not intended to be disabled or bypassed.

Try connecting to your custom joystick with HID Explorer. If it works, consider WebHID API as an alternative. With WebHID you can read the input report into a buffer, then parse the buffer to extract the values for each control.