Description
Use the chrome.usb API to interact with connected USB devices. This API provides access to USB operations from within the context of an app. Using this API, apps can function as drivers for hardware devices. Errors generated by this API are reported by setting runtime.lastError and executing the function's regular callback. The callback's regular parameters will be undefined in this case.
Permissions
usbTypes
ConfigDescriptor
Properties
- 
    activeboolean Chrome 47+Is this the active configuration? 
- 
    configurationValuenumber The configuration number. 
- 
    descriptionstring optional Description of the configuration. 
- 
    extra_dataArrayBuffer Extra descriptor data associated with this configuration. 
- 
    interfacesAvailable interfaces. 
- 
    maxPowernumber The maximum power needed by this device in milliamps (mA). 
- 
    remoteWakeupboolean The device supports remote wakeup. 
- 
    selfPoweredboolean The device is self-powered. 
ConnectionHandle
Properties
- 
    handlenumber An opaque handle representing this connection to the USB device and all associated claimed interfaces and pending transfers. A new handle is created each time the device is opened. The connection handle is different from Device.device.
- 
    productIdnumber The product ID. 
- 
    vendorIdnumber The device vendor ID. 
ControlTransferInfo
Properties
- 
    dataArrayBuffer optional The data to transmit (required only by output transfers). 
- 
    directionThe transfer direction ( "in"or"out").
- 
    indexnumber The wIndexfield, see Ibid.
- 
    lengthnumber optional The maximum number of bytes to receive (required only by input transfers). 
- 
    recipientThe transfer target. The target given by indexmust be claimed if"interface"or"endpoint".
- 
    requestnumber The bRequestfield, see Universal Serial Bus Specification Revision 1.1 § 9.3.
- 
    requestTypeThe request type. 
- 
    timeoutnumber optional Chrome 43+Request timeout (in milliseconds). The default value 0indicates no timeout.
- 
    valuenumber The wValuefield, see Ibid.
Device
Properties
- 
    devicenumber An opaque ID for the USB device. It remains unchanged until the device is unplugged. 
- 
    manufacturerNamestring Chrome 46+The iManufacturer string read from the device, if available. 
- 
    productIdnumber The product ID. 
- 
    productNamestring Chrome 46+The iProduct string read from the device, if available. 
- 
    serialNumberstring Chrome 46+The iSerialNumber string read from the device, if available. 
- 
    vendorIdnumber The device vendor ID. 
- 
    versionnumber Chrome 51+The device version (bcdDevice field). 
DeviceFilter
Properties
- 
    interfaceClassnumber optional USB interface class, matches any interface on the device. 
- 
    interfaceProtocolnumber optional USB interface protocol, checked only if the interface sub-class matches. 
- 
    interfaceSubclassnumber optional USB interface sub-class, checked only if the interface class matches. 
- 
    productIdnumber optional Device product ID, checked only if the vendor ID matches. 
- 
    vendorIdnumber optional Device vendor ID. 
DevicePromptOptions
Properties
- 
    filtersDeviceFilter[] optional Filter the list of devices presented to the user. If multiple filters are provided devices matching any filter will be displayed. 
- 
    multipleboolean optional Allow the user to select multiple devices. 
Direction
Direction, Recipient, RequestType, and TransferType all map to their namesakes within the USB specification.
Enum
"in"  "out" 
 
 
EndpointDescriptor
Properties
- 
    addressnumber Endpoint address. 
- 
    directionTransfer direction. 
- 
    extra_dataArrayBuffer Extra descriptor data associated with this endpoint. 
- 
    maximumPacketSizenumber Maximum packet size. 
- 
    pollingIntervalnumber optional Polling interval (interrupt and isochronous only). 
- 
    synchronizationSynchronizationType optional Transfer synchronization mode (isochronous only). 
- 
    typeTransfer type. 
- 
    usageUsageType optional Endpoint usage hint. 
EnumerateDevicesAndRequestAccessOptions
Properties
- 
    interfaceIdnumber optional The interface ID to request access to. Only available on Chrome OS. It has no effect on other platforms. 
- 
    productIdnumber The product ID. 
- 
    vendorIdnumber The device vendor ID. 
EnumerateDevicesOptions
Properties
- 
    filtersDeviceFilter[] optional A device matching any given filter will be returned. An empty filter list will return all devices the app has permission for. 
- 
    productIdnumber optional DeprecatedEquivalent to setting DeviceFilter.productId.
- 
    vendorIdnumber optional DeprecatedEquivalent to setting DeviceFilter.vendorId.
GenericTransferInfo
Properties
- 
    dataArrayBuffer optional The data to transmit (required only by output transfers). 
- 
    directionThe transfer direction ( "in"or"out").
- 
    endpointnumber The target endpoint address. The interface containing this endpoint must be claimed. 
- 
    lengthnumber optional The maximum number of bytes to receive (required only by input transfers). 
- 
    timeoutnumber optional Chrome 43+Request timeout (in milliseconds). The default value 0indicates no timeout.
InterfaceDescriptor
Properties
- 
    alternateSettingnumber The interface alternate setting number (defaults to 0
- 
    descriptionstring optional Description of the interface. 
- 
    endpointsAvailable endpoints. 
- 
    extra_dataArrayBuffer Extra descriptor data associated with this interface. 
- 
    interfaceClassnumber The USB interface class. 
- 
    interfaceNumbernumber The interface number. 
- 
    interfaceProtocolnumber The USB interface protocol. 
- 
    interfaceSubclassnumber The USB interface sub-class. 
IsochronousTransferInfo
Properties
- 
    packetLengthnumber The length of each of the packets in this transfer. 
- 
    packetsnumber The total number of packets in this transfer. 
- 
    transferInfoTransfer parameters. The transfer length or data buffer specified in this parameter block is split along packetLengthboundaries to form the individual packets of the transfer.
Recipient
Enum
"device"  "interface"  "endpoint"  "other" 
 
 
 
 
RequestType
Enum
"standard"  "class"  "vendor"  "reserved" 
 
 
 
 
SynchronizationType
For interrupt and isochronous modes, SynchronizationType and UsageType map to their namesakes within the USB specification.
Enum
"asynchronous"  "adaptive"  "synchronous" 
 
 
 
TransferResultInfo
Properties
- 
    dataArrayBuffer optional The data returned by an input transfer. undefinedfor output transfers.
- 
    resultCodenumber optional A value of 0indicates that the transfer was a success. Other values indicate failure.
TransferType
Enum
"control"  "interrupt"  "isochronous"  "bulk" 
 
 
 
 
UsageType
Enum
"data"  "feedback"  "explicitFeedback"  "periodic"  "notification" 
 
 
 
 
 
Methods
bulkTransfer()
chrome.usb.bulkTransfer(
handle: ConnectionHandle,
transferInfo: GenericTransferInfo,
callback?: function,
): Promise<TransferResultInfo>
Performs a bulk transfer on the specified device.
Parameters
- 
    handleAn open connection to the device. 
- 
    transferInfoThe transfer parameters. 
- 
    callbackfunction optional The callbackparameter looks like:(info: TransferResultInfo) => void - 
    info
 
- 
    
Returns
- 
            Promise<TransferResultInfo> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
claimInterface()
chrome.usb.claimInterface(
handle: ConnectionHandle,
interfaceNumber: number,
callback?: function,
): Promise<void>
Claims an interface on a USB device. Before data can be transfered to an interface or associated endpoints the interface must be claimed. Only one connection handle can claim an interface at any given time. If the interface is already claimed, this call will fail.
releaseInterface should be called when the interface is no longer needed.
Parameters
- 
    handleAn open connection to the device. 
- 
    interfaceNumbernumber The interface to be claimed. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
closeDevice()
chrome.usb.closeDevice(
handle: ConnectionHandle,
callback?: function,
): Promise<void>
Closes a connection handle. Invoking operations on a handle after it has been closed is a safe operation but causes no action to be taken.
Parameters
- 
    handleThe ConnectionHandleto close.
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
controlTransfer()
chrome.usb.controlTransfer(
handle: ConnectionHandle,
transferInfo: ControlTransferInfo,
callback?: function,
): Promise<TransferResultInfo>
Performs a control transfer on the specified device.
Control transfers refer to either the device, an interface or an endpoint. Transfers to an interface or endpoint require the interface to be claimed.
Parameters
- 
    handleAn open connection to the device. 
- 
    transferInfo
- 
    callbackfunction optional The callbackparameter looks like:(info: TransferResultInfo) => void - 
    info
 
- 
    
Returns
- 
            Promise<TransferResultInfo> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
findDevices()
chrome.usb.findDevices(
options: EnumerateDevicesAndRequestAccessOptions,
callback?: function,
): Promise<ConnectionHandle[]>
Finds USB devices specified by the vendor, product and (optionally) interface IDs and if permissions allow opens them for use.
If the access request is rejected or the device fails to be opened a connection handle will not be created or returned.
Calling this method is equivalent to calling getDevices followed by openDevice for each device.
Parameters
- 
    The properties to search for on target devices. 
- 
    callbackfunction optional The callbackparameter looks like:(handles: ConnectionHandle[]) => void - 
    handles
 
- 
    
Returns
- 
            Promise<ConnectionHandle[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getConfiguration()
chrome.usb.getConfiguration(
handle: ConnectionHandle,
callback?: function,
): Promise<ConfigDescriptor>
Gets the configuration descriptor for the currently selected configuration.
Parameters
- 
    handleAn open connection to the device. 
- 
    callbackfunction optional The callbackparameter looks like:(config: ConfigDescriptor) => void - 
    config
 
- 
    
Returns
- 
            Promise<ConfigDescriptor> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getConfigurations()
chrome.usb.getConfigurations(
device: Device,
callback?: function,
): Promise<ConfigDescriptor[]>
Returns the full set of device configuration descriptors.
Parameters
- 
    deviceThe Deviceto fetch descriptors from.
- 
    callbackfunction optional The callbackparameter looks like:(configs: ConfigDescriptor[]) => void - 
    configs
 
- 
    
Returns
- 
            Promise<ConfigDescriptor[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getDevices()
chrome.usb.getDevices(
options: EnumerateDevicesOptions,
callback?: function,
): Promise<Device[]>
Enumerates connected USB devices.
Parameters
Returns
- 
            Promise<Device[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getUserSelectedDevices()
chrome.usb.getUserSelectedDevices(
options: DevicePromptOptions,
callback?: function,
): Promise<Device[]>
Presents a device picker to the user and returns the Devices selected. If the user cancels the picker devices will be empty. A user gesture is required for the dialog to display. Without a user gesture, the callback will run as though the user cancelled.
Parameters
Returns
- 
            Promise<Device[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
interruptTransfer()
chrome.usb.interruptTransfer(
handle: ConnectionHandle,
transferInfo: GenericTransferInfo,
callback?: function,
): Promise<TransferResultInfo>
Performs an interrupt transfer on the specified device.
Parameters
- 
    handleAn open connection to the device. 
- 
    transferInfoThe transfer parameters. 
- 
    callbackfunction optional The callbackparameter looks like:(info: TransferResultInfo) => void - 
    info
 
- 
    
Returns
- 
            Promise<TransferResultInfo> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
isochronousTransfer()
chrome.usb.isochronousTransfer(
handle: ConnectionHandle,
transferInfo: IsochronousTransferInfo,
callback?: function,
): Promise<TransferResultInfo>
Performs an isochronous transfer on the specific device.
Parameters
- 
    handleAn open connection to the device. 
- 
    transferInfo
- 
    callbackfunction optional The callbackparameter looks like:(info: TransferResultInfo) => void - 
    info
 
- 
    
Returns
- 
            Promise<TransferResultInfo> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
listInterfaces()
chrome.usb.listInterfaces(
handle: ConnectionHandle,
callback?: function,
): Promise<InterfaceDescriptor[]>
Lists all interfaces on a USB device.
Parameters
- 
    handleAn open connection to the device. 
- 
    callbackfunction optional The callbackparameter looks like:(descriptors: InterfaceDescriptor[]) => void - 
    descriptors
 
- 
    
Returns
- 
            Promise<InterfaceDescriptor[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
openDevice()
chrome.usb.openDevice(
device: Device,
callback?: function,
): Promise<ConnectionHandle>
Opens a USB device returned by getDevices.
Parameters
- 
    deviceThe Deviceto open.
- 
    callbackfunction optional The callbackparameter looks like:(handle: ConnectionHandle) => void - 
    handle
 
- 
    
Returns
- 
            Promise<ConnectionHandle> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
releaseInterface()
chrome.usb.releaseInterface(
handle: ConnectionHandle,
interfaceNumber: number,
callback?: function,
): Promise<void>
Releases a claimed interface.
Parameters
- 
    handleAn open connection to the device. 
- 
    interfaceNumbernumber The interface to be released. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
requestAccess()
chrome.usb.requestAccess(
device: Device,
interfaceId: number,
callback?: function,
): Promise<boolean>
This function was Chrome OS specific and calling it on other platforms would fail. This operation is now implicitly performed as part of openDevice and this function will return true on all platforms.
Requests access from the permission broker to a device claimed by Chrome OS if the given interface on the device is not claimed.
Parameters
- 
    deviceThe Deviceto request access to.
- 
    interfaceIdnumber The particular interface requested. 
- 
    callbackfunction optional The callbackparameter looks like:(success: boolean) => void - 
    successboolean 
 
- 
    
Returns
- 
            Promise<boolean> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
resetDevice()
chrome.usb.resetDevice(
handle: ConnectionHandle,
callback?: function,
): Promise<boolean>
Tries to reset the USB device. If the reset fails, the given connection handle will be closed and the USB device will appear to be disconnected then reconnected. In this case getDevices or findDevices must be called again to acquire the device.
Parameters
- 
    handleA connection handle to reset. 
- 
    callbackfunction optional The callbackparameter looks like:(success: boolean) => void - 
    successboolean 
 
- 
    
Returns
- 
            Promise<boolean> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
setConfiguration()
chrome.usb.setConfiguration(
handle: ConnectionHandle,
configurationValue: number,
callback?: function,
): Promise<void>
Select a device configuration.
This function effectively resets the device by selecting one of the device's available configurations. Only configuration values greater than 0 are valid however some buggy devices have a working configuration 0 and so this value is allowed.
Parameters
- 
    handleAn open connection to the device. 
- 
    configurationValuenumber 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
setInterfaceAlternateSetting()
chrome.usb.setInterfaceAlternateSetting(
handle: ConnectionHandle,
interfaceNumber: number,
alternateSetting: number,
callback?: function,
): Promise<void>
Selects an alternate setting on a previously claimed interface.
Parameters
- 
    handleAn open connection to the device where this interface has been claimed. 
- 
    interfaceNumbernumber The interface to configure. 
- 
    alternateSettingnumber The alternate setting to configure. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
Events
onDeviceAdded
chrome.usb.onDeviceAdded.addListener(
callback: function,
)
Event generated when a device is added to the system. Events are only broadcast to apps and extensions that have permission to access the device. Permission may have been granted at install time, when the user accepted an optional permission (see permissions.request), or through getUserSelectedDevices.
Parameters
- 
    callbackfunction The callbackparameter looks like:(device: Device) => void - 
    device
 
- 
    
onDeviceRemoved
chrome.usb.onDeviceRemoved.addListener(
callback: function,
)
Event generated when a device is removed from the system. See onDeviceAdded for which events are delivered.