diff --git a/src/webusb_device.rs b/src/webusb_device.rs index dd70374..756d647 100644 --- a/src/webusb_device.rs +++ b/src/webusb_device.rs @@ -779,18 +779,18 @@ impl UsbDevice { self.device_guard().is_some() } - #[napi(getter, ts_return_type = "USBConfiguration")] + #[napi(getter, ts_return_type = "USBConfiguration | null")] pub fn configuration(&self) -> Result> { let device = match self.device_guard().as_ref() { Some(device) => device.clone(), None => self._open()?, }; - let config = device - .active_configuration() - .map_err(|e| napi::Error::from_reason(format!("configuration error: {e}")))?; - - Ok(Some(UsbConfiguration::new(&self, &device, config)?)) + // Null when the device is unconfigured, as per WebUSB spec + match device.active_configuration() { + Ok(config) => Ok(Some(UsbConfiguration::new(&self, &device, config)?)), + Err(_) => Ok(None), + } } #[napi(getter, ts_return_type = "Array")]