Skip to main content
Version: 0.0.24

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). However, it might return non-ADB devices as well.

To only get ADB devices, AdbDaemonWebUsbDeviceManager#getDevices method also accepts a filters option, to only return devices that match the specified criteria.

declare class AdbDaemonWebUsbDeviceManager {
getDevices(filters?: AdbDeviceFilter[]): Promise<AdbDaemonWebUsbDevice[]>;
}
note

See Device filter for more information about how does the filter work and how to define a filter.

The filters option defaults to [ADB_DEFAULT_DEVICE_FILTER], which matches the ADB interface. Unless your ADB devices uses a different identifier, or you want to select a specific device, you can just call AdbDaemonWebUsbDeviceManager#getDevices without any arguments:

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.

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];

Examples

To select a specific manufacturer and model:

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

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

To allow multiple manufacturers/models:

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

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