From 8524c76f668711509fa4fcf0cffb2f92e6f53e80 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 5 Apr 2018 00:41:05 +0300 Subject: [PATCH] setBadgeText has a callback in Chrome 67+ --- background/background.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/background/background.js b/background/background.js index ed9aa30d..8f7249bb 100644 --- a/background/background.js +++ b/background/background.js @@ -409,8 +409,12 @@ function updateIcon({tab, styles}) { chrome.browserAction.setBadgeBackgroundColor({color}); } - if (tabIcon.text !== text) { - tabIcon.text = text; + if (tabIcon.text === text) return; + tabIcon.text = text; + try { + // Chrome supports the callback since 67.0.3381.0, see https://crbug.com/451320 + chrome.browserAction.setBadgeText({text, tabId: tab.id}, ignoreChromeError); + } catch (e) { setTimeout(() => { getTab(tab.id).then(realTab => { // skip pre-rendered tabs