diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 14e87d3d74f5..9615962ac66b 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -147,12 +147,12 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { let asyncPopup = false // menu.popup(x, y, positioningItem) - if (typeof window !== 'object' || window.constructor !== BrowserWindow) { + if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) { // Shift. positioningItem = y y = x x = window - window = BrowserWindow.getFocusedWindow() + window = null } // menu.popup(window, {}) @@ -164,6 +164,9 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { asyncPopup = options.async } + // Default to showing in focused window. + if (window == null) window = BrowserWindow.getFocusedWindow() + // Default to showing under mouse location. if (typeof x !== 'number') x = -1 if (typeof y !== 'number') y = -1 diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index c43a28823915..6c03800bcdec 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -253,7 +253,7 @@ WebContents.prototype._init = function () { this.on('pepper-context-menu', function (event, params) { // Access Menu via electron.Menu to prevent circular require const menu = electron.Menu.buildFromTemplate(params.menu) - menu.popup(params.x, params.y) + menu.popup(event.sender.getOwnerBrowserWindow(), params.x, params.y) }) // The devtools requests the webContents to reload.