Browse Source

fix: ensure bluetooth devices are not returned by default (#32178)

Samuel Attard 3 years ago
parent
commit
a11f5cbb27
2 changed files with 10 additions and 0 deletions
  1. 2 0
      docs/api/web-contents.md
  2. 8 0
      lib/browser/api/web-contents.ts

+ 2 - 0
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')
 

+ 8 - 0
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);