Fix error logs when WebUSB is not available

When perfetto is run under another host name, like when we want to test
the extension, there were a lot of errors because webUSB is not
available on non-https sites.

Change-Id: I755c1b5ddf918e107b620ac749cb5ff9cecfa356
diff --git a/ui/src/controller/adb.ts b/ui/src/controller/adb.ts
index 3bbaa37..54c6733 100644
--- a/ui/src/controller/adb.ts
+++ b/ui/src/controller/adb.ts
@@ -71,7 +71,11 @@
   }
 
   async getPairedDevices() {
-    return navigator.usb.getDevices();
+    try {
+      return navigator.usb.getDevices();
+    } catch (e) {  // WebUSB not available.
+      return Promise.resolve([]);
+    }
   }
 
   async connect(device: USBDevice): Promise<void> {
diff --git a/ui/src/frontend/index.ts b/ui/src/frontend/index.ts
index 4a3081b..3790f61 100644
--- a/ui/src/frontend/index.ts
+++ b/ui/src/frontend/index.ts
@@ -248,9 +248,12 @@
   }
 
   updateAvailableAdbDevices();
-  navigator.usb.addEventListener('connect', updateAvailableAdbDevices);
-  navigator.usb.addEventListener('disconnect', updateAvailableAdbDevices);
-
+  try {
+    navigator.usb.addEventListener('connect', updateAvailableAdbDevices);
+    navigator.usb.addEventListener('disconnect', updateAvailableAdbDevices);
+  } catch (e) {
+    console.error('WebUSB API not supported');
+  }
   // This forwards the messages from the controller to the extension
   extensionLocalChannel.port2.onmessage = ({data}) => {
     if (extensionPort) extensionPort.postMessage(data);