e01.org

USBConnectionEvent

WebUSB API

WebUSB API

The **`USBConnectionEvent`** interface of the is the event type passed to `USB` connect and disconnect events when the user agent detects that a new USB device has been connected or disconnected.

## Constructor

- USBConnectionEvent()
- : Returns a `USBConnectionEvent` object.

## Instance properties

- USBConnectionEvent.device
- : Returns a USBDevice object representing the current device.

## Examples

In the following example listening for connect and disconnect events is used to add and remove the devices from the user interface of an application.

```js
navigator.usb.addEventListener("connect", (event) => {
// Add event.device to the UI.
});

navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
```

## Specifications

## Browser compatibility

source: MDN Web Docs mirror · page

Cite this

"USBConnectionEvent". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/USBConnectionEvent

JSON record · API collection · citation policy