Skip to content

Commit

Permalink
fix: ensure bluetooth devices are not returned by default (#32195)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
  • Loading branch information
trop[bot] and MarshallOfSound committed Dec 16, 2021
1 parent 9961c7a commit a6f0482
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/api/web-contents.md
Expand Up @@ -730,6 +730,8 @@ first available device will be selected. `callback` should be called with
`deviceId` to be selected, passing empty string to `callback` will
cancel the request.

If no event listener is added for this event, all bluetooth requests will be cancelled.

```javascript
const { app, BrowserWindow } = require('electron')

Expand Down
8 changes: 8 additions & 0 deletions lib/browser/api/web-contents.ts
Expand Up @@ -681,6 +681,14 @@ WebContents.prototype._init = function () {
}
});

this.on('select-bluetooth-device', (event, devices, callback) => {
if (this.listenerCount('select-bluetooth-device') === 0) {
// Cancel it if there are no handlers
event.preventDefault();
callback('');
}
});

const event = process._linkedBinding('electron_browser_event').createEmpty();
app.emit('web-contents-created', event, this);

Expand Down

0 comments on commit a6f0482

Please sign in to comment.