From dfdff2c452a6c30f3008953e64bc2d4bab933f42 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 15 Dec 2021 12:33:02 +1300 Subject: [PATCH] fix: ensure bluetooth devices are not returned by default --- docs/api/web-contents.md | 2 ++ lib/browser/api/web-contents.ts | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 5c1e857fe24b5..ce21c37136649 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -731,6 +731,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 8bb863a0eb212..e3847224535d5 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -738,6 +738,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);