diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 59ec589e82a8a..bbf41cadb379c 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -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') diff --git a/lib/browser/api/web-contents.ts b/lib/browser/api/web-contents.ts index 4234d047495eb..a0211b7d4ea20 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -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);