0

Im trying to use DART's chrome.usb API in a angular-4 dart web-application. But it keeps throwing an exception as _usb is null.

if (_usb == null) _throwNotAvailable();

As a workaround, I wrote a DART wrapper around a javascript library (inspired by arduino webusb demo). This works. Also when chrome-app device-info as en example, Im able to communicate to a USB device endpoint; however, the example is not written in DART.

However, I'm confused why using DART's chrome.usb, it isn't working. I'll prefer to use the already existing chrome.usb API as reinventing the wheel.

Reading certain websites, they indicate that chrome.usb is limited to web-applications or extensions and need a manifest.json file for the proper permissions (I tried the manifest file without success). Not sure if I misunderstood those websites (As I think writing a SPA front-end with Angular-dart is considered a web-application), plus when using a DART wrapper around a javascript library, it works fine.

Any suggestions are welcome.

Bas E
  • 96
  • 1
  • 7
  • When it works in JS it should work in Dart. I'd create a bug report. – Günter Zöchbauer Feb 21 '18 at 04:19
  • Chrome app is a different thing. It's not a web app, not a SPA. Also, it's deprecated. Chrome extensions don't have access to chrome.usb. Use WebUSB like you do already. – wOxxOm Feb 21 '18 at 08:41

1 Answers1

1

chrome.usb and WebUSB are two different APIs. chrome.usb is only available in Chrome Apps, which are deprecated. WebUSB is available on any web page (as long as its served over HTTPS). If the Dart wrapper you are using only supports calling the chrome.usb API then you'll need to write a new one that calls the WebUSB API.

Reilly Grant
  • 5,590
  • 1
  • 13
  • 23