diff --git a/.eslintrc b/.eslintrc index 8cc63436..73a2efac 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,6 +16,7 @@ globals: URLS: false BG: false notifyAllTabs: false + getTab: false getActiveTab: false getActiveTabRealURL: false getTabRealURL: false diff --git a/background.js b/background.js index 415de5ae..0790cea1 100644 --- a/background.js +++ b/background.js @@ -210,12 +210,7 @@ function updateIcon(tab, styles) { return; } if (styles) { - // check for not-yet-existing tabs e.g. omnibox instant search - chrome.tabs.get(tab.id, () => { - if (!chrome.runtime.lastError) { - stylesReceived(styles); - } - }); + stylesReceived(styles); return; } getTabRealURL(tab).then(url => @@ -247,11 +242,14 @@ function updateIcon(tab, styles) { // TODO: add Edge preferred sizes: 20, 25, 30, 40 }, }, () => { - if (!chrome.runtime.lastError) { - // Vivaldi bug workaround: setBadgeText must follow setBadgeBackgroundColor - chrome.browserAction.setBadgeBackgroundColor({color}); - chrome.browserAction.setBadgeText({text, tabId: tab.id}); + if (chrome.runtime.lastError) { + return; } + // Vivaldi bug workaround: setBadgeText must follow setBadgeBackgroundColor + chrome.browserAction.setBadgeBackgroundColor({color}); + getTab(tab.id).then(() => { + chrome.browserAction.setBadgeText({text, tabId: tab.id}); + }); }); } } diff --git a/messaging.js b/messaging.js index b688270a..0a1ad059 100644 --- a/messaging.js +++ b/messaging.js @@ -87,6 +87,13 @@ function notifyAllTabs(msg) { } +function getTab(id) { + return new Promise(resolve => + chrome.tabs.get(id, tab => + !chrome.runtime.lastError && resolve(tab))); +} + + function getActiveTab() { return new Promise(resolve => chrome.tabs.query({currentWindow: true, active: true}, tabs =>