Failed to connect to USB on chromebook: Permission to access device was denied

别说谁变了你拦得住时间么 提交于 2019-12-24 17:39:46

问题


I'm writing app for chromebook that has to communicate with specific USB device. The device is present in the list of found devices, that comes from callback:

   var VENDOR_ID = 5824, PRODUCT_ID = 1159;

   document.getElementById("request-permission").addEventListener('click', function() {
    chrome.permissions.request({
            permissions: [{
                'usbDevices': [{
                    'vendorId': VENDOR_ID,
                    "productId": PRODUCT_ID
                }]
            }]
        },
        function(result) {
            if (result) {
                console.log('App was granted the "usbDevices" permission.');
                getDevices();
            }
        }
    });
});


function getDevices() {
    chrome.usb.getDevices({
        vendorId: VENDOR_ID,
        productId: PRODUCT_ID
    }, function(devices) {
        if (chrome.runtime.lastError !== undefined) {
            console.warn('chrome.usb.getDevices error: ' + chrome.runtime.lastError.message);
            return;
        }
        if (devices) {
            if (devices.length > 0) {
                for (var device of devices)
                    openUsbDevice(device);
            }
        }
    }); 
}

So I can see my device successfully, but when I'm trying to open it , it fails:

chrome.usb.openDevice(device, function(handle) {
        if (chrome.runtime.lastError != undefined) {
          console.log('Failed to open device: '+chrome.runtime.lastError.message);
        } else {
          populateDeviceInfo(handle, function () {
              chrome.usb.closeDevice(handle);
            });
        }
      });

And I'm receiving error in console: Failed to open device: Permission to access device was denied

I have all required usb permissions declared in manifest.js:

  "permissions" : [
    "usb"
  ],
  "optional_permissions" : [{
    "usbDevices" : [
        {
          "productId" : 1159,
          "vendorId" : 5824
        }
      ]
  }],

I've also tried another api functions, like chrome.usb.findDevices and chrome.usb.requestAccess , but result is the same. At same time my nexus 7 device e.g. is recognised successfully via usb. Any ideas why that can be or guesses how to make my usb device become accessible? I've faced with this only on Acer Chromebook c7 (Chrome OS v.44) and on Mac I hadn't such issue.


回答1:


Open chrome://system and expand the "syslog" section. You will find a series of messages from "permission_broker" for each device you try to open and the rule that caused it to deny access.

The most common reason is "DenyClaimedUsbDeviceRule" which denies access to devices that are claimed by another application or a kernel driver. Access is denied in this case for security reasons. Chrome OS does not want a Chrome App to be able to override any policies normally enforced by the kernel for devices that it has support for. You should use a higher level API (such as chrome.fileSystem for storage devices or navigator.getUserMedia for webcams and audio adapters).



来源:https://stackoverflow.com/questions/32335206/failed-to-connect-to-usb-on-chromebook-permission-to-access-device-was-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!