From 5d5d295ebb7bab78f06ff83494dfae1974e176ec Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 18:55:04 +0200 Subject: [PATCH] fix(scripts): wrong background script performance --- scripts/background.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/background.js b/scripts/background.js index 40f6310..05363d9 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -209,7 +209,14 @@ const updateState = (tabId, state) => { chrome.runtime.onMessage.addListener((request, sender, responseCallback) => { const hasPermission = !sender.frameId || sender.frameId === 0; - const tabId = sender.tab.id; + let tabId = sender.tab ? sender.tab.id : undefined; + + if (!tabId) { + chrome.tabs.query( + { active: true, currentWindow: true }, + (tabs) => (tabId = tabs[0] ? tabs[0].id : 0) + ); + } switch (request.type) { case "DISABLE_ICON":