thegecko/webusb

TypeError: Illegal Constructor

Opened this issue · 6 comments

Anyone run into this issue?

Using the coding from your selector.js. I added a connect button to execute but keep running into this pop-up error when executing. Thoughts?

You added a button and see a popup, where are you running the library?

const devicesFound = devices => new Promise(resolve => {
    process.stdin.setRawMode(true);
    process.stdin.setEncoding("utf8");
    process.stdin.on("readable", () => {
        const input = process.stdin.read();

        if (input === "\u0003") {
            process.exit();
        } else {
            const index = parseInt(input);
            if (index && index <= devices.length) {
                process.stdin.setRawMode(false);
                resolve(devices[index - 1]);
            }
        }
    });

    console.log("select a device to see it's active configuration:");
    devices.forEach((device, index) => {
        console.log(`${index + 1}: ${device.productName || device.serialNumber}`);
    });
});

const startDevice = async () => {
   const usb = new USB({
      devicesFound
  });

  (async () => {
      try {
          const device = await usb.requestDevice({
              filters: [{vendorId: 0x0781}, {productId: 0xD437}]
          });

          console.log(JSON.stringify(device, (key, value) => {
              if (key === "interfaces") return `[${value.length}...]`;
              return value;
          }, "\t"));
      } catch (error) {
          console.log(error.message);
      }
  })
await device.open();

just used query selector

const initEvents = () => {document.querySelector('#connect').addEventListener('click', async () => {
    try {device = await startDevice()}

You're running this in a browser?
You should use the native webusb.

Using electron

Not tried it, but I believe you need to run this in the backend process in Electron.

@MasterCodeIT How are you importing/requiring the library? Usually it's not necessary to instantiate the class like you did in

const usb = new USB({
      devicesFound
  });