Ver Fonte

Merge pull request #1708 from zthxxx/fix/get-active-tab

fix: ensure correct active tab detection from the extension dashboard
Ahmad Kholid há 1 ano atrás
pai
commit
d7fedcf08f
2 ficheiros alterados com 8 adições e 17 exclusões
  1. 1 0
      src/manifest.chrome.json
  2. 7 17
      src/utils/helper.js

+ 1 - 0
src/manifest.chrome.json

@@ -55,6 +55,7 @@
   ],
   "permissions": [
     "tabs",
+    "activeTab",
     "proxy",
     "alarms",
     "storage",

+ 7 - 17
src/utils/helper.js

@@ -2,29 +2,19 @@ import browser from 'webextension-polyfill';
 
 export async function getActiveTab() {
   try {
-    let windowId = null;
     const tabsQuery = {
       active: true,
       url: '*://*/*',
     };
-    const extURL = browser.runtime.getURL('');
-    const windows = await browser.windows.getAll({ populate: true });
-    for (const browserWindow of windows) {
-      const [tab] = browserWindow.tabs;
-      const isDashboard =
-        browserWindow.tabs.length === 1 && tab.url?.includes(extURL);
-
-      if (isDashboard) {
-        await browser.windows.update(browserWindow.id, {
-          focused: false,
-        });
-      } else if (browserWindow.focused) {
-        windowId = browserWindow.id;
-      }
-    }
+
+    const window = await browser.windows.getLastFocused({
+      populate: true,
+      windowTypes: ['normal'],
+    });
+    const windowId = window.id;
 
     if (windowId) tabsQuery.windowId = windowId;
-    else if (windows.length > 2) tabsQuery.lastFocusedWindow = true;
+    else tabsQuery.lastFocusedWindow = true;
 
     const [tab] = await browser.tabs.query(tabsQuery);