From 8368b887f7d3277f14e7c4976e4c0848a3cc0112 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 15 Dec 2021 14:25:47 -0800 Subject: [PATCH] fix: ensure bluetooth devices are not returned by default (#32198) Co-authored-by: Samuel Attard --- 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 43eee11e5db43..54f322ffa5d04 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -736,6 +736,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 e0336ccf62885..56582425a4180 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -749,6 +749,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);