I am trying to connect to Android phone using WebUSB with USB debugging OFF. But It return an error DOMException Acces denied
.
Basically, I want my PC to connect as USB client (like Keyboard or any usb device) to Android phone.
However, Other USB devices (like USB audio device) are not giving any error. I recieve access error on device.open()
let device = null
let configValue = 0
let interfaceValue = 0
const connect = async() => {
try {
device = await navigator.usb.requestDevice({
filters : [{}]
});
await device.open()
// if(device.configurations.length > 0){
// configValue = device.configuration.configurationValue
// interfaceValue = device.configuration.interfaces[0].interfaceNumber
// await device.selectConfiguration(configValue)
// await device.claimInterface(interfaceValue)
// }
console.log(device);
} catch (error) {
console.log(error);
}
}
CodePudding user response:
When an Android device does not have USB debugging enabled it does not provide a USB interface that Windows will allow a user-space application such as your web browser to claim. This is why you get the "Access denied" error.
It sounds like what you are trying to do is have your computer act as a USB peripheral so that the phone connects to it as the USB host. This is not supported by most desktop USB controllers and this mode is not supported by the WebUSB API.