From dce3b4aa08133d40d6df809ebe1d9ffa7487e9f9 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 26 Feb 2026 04:03:45 +0700 Subject: [PATCH] Center approval popup over focused window to avoid macOS Space switch Use getLastFocused to find the current Chrome window and position the approval popup centered over it. This keeps the popup on the same macOS virtual desktop instead of switching Spaces. --- src/background/index.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 46314e7..fc1e330 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -89,19 +89,32 @@ function requestApproval(origin, hostname) { pendingApprovals[id] = { origin, hostname, resolve }; const popupUrl = runtime.getURL("src/popup/index.html?approval=" + id); - windowsApi.create( - { + const popupWidth = 400; + const popupHeight = 500; + + // Center the popup over the focused window so macOS keeps it + // on the same Space instead of switching desktops. + windowsApi.getLastFocused((currentWin) => { + const opts = { url: popupUrl, type: "popup", - width: 400, - height: 500, - }, - (win) => { + width: popupWidth, + height: popupHeight, + }; + if (currentWin) { + opts.left = Math.round( + currentWin.left + (currentWin.width - popupWidth) / 2, + ); + opts.top = Math.round( + currentWin.top + (currentWin.height - popupHeight) / 2, + ); + } + windowsApi.create(opts, (win) => { if (win) { pendingApprovals[id].windowId = win.id; } - }, - ); + }); + }); }); }