From 257fda4d1d85b7b446c0bed984b008daf3e90b82 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 11 Apr 2017 06:51:32 +0300 Subject: [PATCH] updateIcon: use the old flow to avoid "no tab" errors --- messaging.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/messaging.js b/messaging.js index 0de622f5..b62c9673 100644 --- a/messaging.js +++ b/messaging.js @@ -97,13 +97,12 @@ function updateIcon(tab, styles) { }); return; } - (isNTP ? getTabRealURL(tab) : Promise.resolve(tab.url)) - .then(url => getStylesSafe({ - matchUrl: url, - enabled: true, - asHash: true, - })) - .then(stylesReceived); + if (isNTP) { + getTabRealURL(tab).then(url => + getStyles({matchUrl: url, enabled: true, asHash: true}, stylesReceived)); + } else { + getStyles({matchUrl: tab.url, enabled: true, asHash: true}, stylesReceived); + } function stylesReceived(styles) { let numStyles = styles.length; @@ -129,10 +128,13 @@ function updateIcon(tab, styles) { 38: `images/icon/38${postfix}.png`, // TODO: add Edge preferred sizes: 20, 25, 30, 40 }, - }, ignoreChromeError); - // Vivaldi bug workaround: setBadgeText must follow setBadgeBackgroundColor - chrome.browserAction.setBadgeBackgroundColor({color}); - chrome.browserAction.setBadgeText({text, tabId: tab.id}); + }, () => { + if (!chrome.runtime.lastError) { + // Vivaldi bug workaround: setBadgeText must follow setBadgeBackgroundColor + chrome.browserAction.setBadgeBackgroundColor({color}); + chrome.browserAction.setBadgeText({text, tabId: tab.id}); + } + }); } }