From bf1ead60322289536ce1029069a958a12ecadf73 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Thu, 25 Apr 2019 10:05:11 +0200 Subject: [PATCH] Perf bugfix: reduce number of times badge counter is refreshed (#136) --- src/background.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/background.js b/src/background.js index d36d7b8..d197442 100644 --- a/src/background.js +++ b/src/background.js @@ -34,19 +34,18 @@ chrome.browserAction.setBadgeBackgroundColor({ // watch for tab updates chrome.tabs.onUpdated.addListener((tabId, info) => { - // ignore non-complete status - if (info.status !== "complete") { - return; - } - // unregister any auth listeners for this tab - if (authListeners[tabId]) { - chrome.webRequest.onAuthRequired.removeListener(authListeners[tabId]); - delete authListeners[tabId]; + if (info.status === "complete") { + if (authListeners[tabId]) { + chrome.webRequest.onAuthRequired.removeListener(authListeners[tabId]); + delete authListeners[tabId]; + } } - // show number of matching passwords in a badge - updateMatchingPasswordsCount(tabId); + // refresh badge counter when url in a tab changes + if (info.url) { + updateMatchingPasswordsCount(tabId); + } }); // handle incoming messages