WebUSB: The requested interface implements a protected class
Asked Answered
Z

2

8

I'm trying to use a card reader (https://www.ewent-online.com/tcpdf/pdf/ew/p/EW1052/) to read a Health Card.

This is the code (copy-pasted from the official doc: https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web):

var device;

navigator['usb'].requestDevice({ filters: [] })
.then(selectedDevice => {
    device = selectedDevice;
    return device.open(); // Begin a session.
})
.then(() => device.selectConfiguration(1)) // Select configuration #1 forhe device.
.then(() => device.claimInterface(0)) // Request exclusive control over     interface #2.
.then(() => device.controlTransferOut({
    requestType: 'class',
    recipient: 'interface',
    request: 0x22,
    value: 0x01,
    index: 0x00}
)) // Ready to receive data
.then(() => device.transferIn(5, 64)) // Waiting for 64 bytes of data from endpoint #5.
.then(result => {
    let decoder = new window['TextDecoder']();
    console.log('Received: ' + decoder.decode(result.data));
})
.catch(error => {
    console.log(error);
});

The error is here:

device.claimInterface(0)

For some reason i can't access at the class. I can't figure out hot to make it work, i have read alla stackoverflow related thread without found a solution.

Thanks in advance!

Zamia answered 27/2, 2019 at 16:57 Comment(2)
Did you ever find a good workaround for this?Brice
@Brice no, i didn't work on this topic anymore. In my research i didn't find a solution to this problem.Zamia
S
11

Your device implements the USB CCID class, which is on the list of classes protected by Chrome as announced in the post below. Interfaces implementing these classes cannot be claimed through WebUSB.

https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/LZXocaeCwDw/GLfAffGLAAAJ

Simferopol answered 27/2, 2019 at 20:30 Comment(1)
Thanks for the fast reply! So the device is the problem? There is another smart card reader that work without Chrome limitations?Zamia
C
0

navigator.usb.requestDevice({ filters: [{ vendorId:"set your product vendorId" }] })

// if you have set wrong product vendorId then you show this error

Cabala answered 13/10, 2023 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.