Skip to content

Commit 8a2f487

Browse files
fix: ensure bluetooth devices are not returned by default (#32199)
Co-authored-by: Samuel Attard <[email protected]>
1 parent 66dec80 commit 8a2f487

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/api/web-contents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ first available device will be selected. `callback` should be called with
736736
`deviceId` to be selected, passing empty string to `callback` will
737737
cancel the request.
738738

739+
If no event listener is added for this event, all bluetooth requests will be cancelled.
740+
739741
```javascript
740742
const { app, BrowserWindow } = require('electron')
741743

lib/browser/api/web-contents.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ WebContents.prototype._init = function () {
738738
}
739739
});
740740

741+
this.on('select-bluetooth-device', (event, devices, callback) => {
742+
if (this.listenerCount('select-bluetooth-device') === 0) {
743+
// Cancel it if there are no handlers
744+
event.preventDefault();
745+
callback('');
746+
}
747+
});
748+
741749
const event = process._linkedBinding('electron_browser_event').createEmpty();
742750
app.emit('web-contents-created', event, this);
743751

0 commit comments

Comments
 (0)