Device Access

    The Web Bluetooth API can be used to communicate with bluetooth devices. In order to use this API in Electron, developers will need to handle the associated with the device request.

    This example demonstrates an Electron application that automatically selects the first available bluetooth device when the Test Bluetooth button is clicked.

    • ses.setDevicePermissionHandler(handler) can be used to provide default permissioning to devices without first calling for permission to devices via navigator.hid.requestDevice. Additionally, the default behavior of Electron is to store granted device permision through the lifetime of the corresponding WebContents. If longer term storage is needed, a developer can store granted device permissions (eg when handling the event) and then read from that storage with setDevicePermissionHandler.
    • can be used to disable HID access for specific origins.

    By default Electron employs the same blocklist used by Chromium. If you wish to override this behavior, you can do so by setting the disable-hid-blocklist flag:

    This example demonstrates an Electron application that automatically selects HID devices through and through select-hid-device event on the Session when the Test WebHID button is clicked.

    There are several additional APIs for working with the Web Serial API:

    • The and events on the Session can be used to handle devices being plugged in or unplugged during the navigator.serial.requestPort process.
    • can be used to disable serial access for specific origins.

    This example demonstrates an Electron application that automatically selects serial devices through ses.setDevicePermissionHandler(handler) as well as demonstrating selecting the first available Arduino Uno serial device (if connected) through when the button is clicked.