| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  | function getDeviceDetails (device) { | 
					
						
							| 
									
										
										
										
											2023-03-07 15:36:31 -05:00
										 |  |  |   return device.productName || `Unknown device ${device.deviceId}` | 
					
						
							| 
									
										
										
										
											2022-11-22 16:50:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  | async function testIt () { | 
					
						
							| 
									
										
										
										
											2022-11-22 16:50:32 -05:00
										 |  |  |   const noDevicesFoundMsg = 'No devices found' | 
					
						
							|  |  |  |   const grantedDevices = await navigator.usb.getDevices() | 
					
						
							|  |  |  |   let grantedDeviceList = '' | 
					
						
							| 
									
										
										
										
											2023-02-01 12:59:16 +01:00
										 |  |  |   if (grantedDevices.length > 0) { | 
					
						
							| 
									
										
										
										
											2023-08-31 16:36:43 +02:00
										 |  |  |     for (const device of grantedDevices) { | 
					
						
							| 
									
										
										
										
											2022-11-22 16:50:32 -05:00
										 |  |  |       grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>` | 
					
						
							| 
									
										
										
										
											2023-08-31 16:36:43 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-22 16:50:32 -05:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     grantedDeviceList = noDevicesFoundMsg | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   document.getElementById('granted-devices').innerHTML = grantedDeviceList | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   grantedDeviceList = '' | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     const grantedDevice = await navigator.usb.requestDevice({ | 
					
						
							|  |  |  |       filters: [] | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2023-04-24 07:35:14 -07:00
										 |  |  |     grantedDeviceList += `<hr>${getDeviceDetails(grantedDevice)}</hr>` | 
					
						
							| 
									
										
										
										
											2022-11-22 16:50:32 -05:00
										 |  |  |   } catch (ex) { | 
					
						
							|  |  |  |     if (ex.name === 'NotFoundError') { | 
					
						
							|  |  |  |       grantedDeviceList = noDevicesFoundMsg | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   document.getElementById('granted-devices2').innerHTML = grantedDeviceList | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  | document.getElementById('clickme').addEventListener('click', testIt) |