Skip to main content
Version: next

Get all connected devices

After the user has granted permission to access the device, the next time the user visits the page, the Web app can access the device directly without asking for permission again.

WebUSB USB#getDevices method can be used to get all connected devices (that the user has granted permission to access).

USB#getDevices method doesn't accept filters like USB#requestDevice, so it might return non-ADB devices. Tango's AdbDaemonWebUsbDeviceManager#getDevices accepts the same options as AdbDaemonWebUsbDeviceManager#requestDevice and does the filtering on its own to better support usage with ADB devices.

declare class AdbDaemonWebUsbDeviceManager {
getDevices(
options?: AdbDaemonWebUsbDeviceManager.RequestDeviceOptions
): Promise<AdbDaemonWebUsbDevice[]>;
}

Basic usage:

import { AdbDaemonWebUsbDevice } from "@yume-chan/adb-daemon-webusb";

const devices: AdbDaemonWebUsbDevice[] = await Manager.getDevices();
if (!devices.length) {
alert("No device connected");
return;
}

const device: AdbDaemonWebUsbDevice = devices[0];

Options

The options parameter works the same as in requestDevice. By default, it only returns devices that match the default ADB interface.

info

Some lazy manufacturers use the same serialNumber for all devices. So even if serialNumber is specified, it's still possible that multiple devices will be returned.

To select a specific manufacturer and model:

import { AdbDaemonWebUsbDevice } from "@yume-chan/adb-daemon-webusb";

const devices: AdbDaemonWebUsbDevice[] = await Manager.getDevices({
filters: [
{
vendorId: 0x18d1,
productId: 0x4ee2,
},
],
});

To allow multiple manufacturers/models:

import { AdbDaemonWebUsbDevice } from "@yume-chan/adb-daemon-webusb";

const device: AdbDaemonWebUsbDevice | undefined = await Manager.getDevices({
filters: [
{
vendorId: 0x18d1,
productId: 0x4ee2,
},
{
vendorId: 0x04e8,
productId: 0x6860,
},
],
});