diff --git a/src/ui/utils/imKey.ts b/src/ui/utils/imKey.ts index bde8889c0b0..16bd0663c86 100644 --- a/src/ui/utils/imKey.ts +++ b/src/ui/utils/imKey.ts @@ -28,13 +28,13 @@ export const useImKeyDeviceConnected = () => { useEffect(() => { detectDevice(); - navigator?.usb.addEventListener('connect', onConnect); - navigator?.usb.addEventListener('disconnect', onDisconnect); + navigator.usb?.addEventListener('connect', onConnect); + navigator.usb?.addEventListener('disconnect', onDisconnect); browser.windows.onFocusChanged.addListener(detectDevice); return () => { - navigator?.usb.removeEventListener('connect', onConnect); - navigator?.usb.removeEventListener('disconnect', onDisconnect); + navigator.usb?.removeEventListener('connect', onConnect); + navigator.usb?.removeEventListener('disconnect', onDisconnect); browser.windows.onFocusChanged.removeListener(detectDevice); }; }, []); @@ -49,13 +49,13 @@ const imKeyDevices = [ ]; async function requestImKeyDevice(): Promise { - const device = await navigator?.usb.requestDevice({ + const device = await navigator.usb?.requestDevice({ filters: imKeyDevices, }); return device; } export async function getImKeyDevices(): Promise { - const devices = await navigator?.usb.getDevices(); + const devices = await navigator.usb?.getDevices(); return devices.filter((d) => d.vendorId === imKeyUSBVendorId); } diff --git a/src/ui/utils/keystone.ts b/src/ui/utils/keystone.ts index 8b26ee5e5f8..15f551aa5b1 100644 --- a/src/ui/utils/keystone.ts +++ b/src/ui/utils/keystone.ts @@ -10,7 +10,7 @@ import browser from 'webextension-polyfill'; const navigator = window.navigator as any; export const hasConnectedKeystoneDevice = async () => { - const devices = await navigator?.usb.getDevices(); + const devices = await navigator.usb?.getDevices(); return ( devices.filter((device) => device.vendorId === keystoneUSBVendorId).length > 0 @@ -40,13 +40,13 @@ export const useKeystoneDeviceConnected = () => { useEffect(() => { detectDevice(); - navigator?.usb.addEventListener('connect', onConnect); - navigator?.usb.addEventListener('disconnect', onDisconnect); + navigator.usb?.addEventListener('connect', onConnect); + navigator.usb?.addEventListener('disconnect', onDisconnect); browser.windows.onFocusChanged.addListener(detectDevice); return () => { - navigator?.usb.removeEventListener('connect', onConnect); - navigator?.usb.removeEventListener('disconnect', onDisconnect); + navigator.usb?.removeEventListener('connect', onConnect); + navigator.usb?.removeEventListener('disconnect', onDisconnect); browser.windows.onFocusChanged.removeListener(detectDevice); }; });