From 8bc9e5c2202a68e7f4125c35114d26efb5c5c26f Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Mon, 26 Oct 2026 22:46:03 +0100 Subject: [PATCH] If the user closed the device chooser without selecting a device: treat it as a cancellation, not an error, so no device is returned. --- packages/bluetooth/src/BluetoothManager.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/bluetooth/src/BluetoothManager.ts b/packages/bluetooth/src/BluetoothManager.ts index 45ac039..502e002 100644 --- a/packages/bluetooth/src/BluetoothManager.ts +++ b/packages/bluetooth/src/BluetoothManager.ts @@ -101,10 +101,20 @@ export class BluetoothManager implements IBluetoothManager { ): Promise { const isWebBluetoothSupported = await this.checkWebBluetoothSupport(); if (isWebBluetoothSupported) { - const native = await navigator.bluetooth.requestDevice( - registryItem.options - ); - return native; + try { + const native = await navigator.bluetooth.requestDevice( + registryItem.options + ); + return native; + } catch (err) { + if ((err as DOMException)?.name === 'NotFoundError') { + // The user closed the device chooser without selecting a + // device: this is a cancellation, not an error, so no device + // is returned. + return undefined; + } + throw err; + } } else { return; }