try to avoid setBadgeText errors

This commit is contained in:
tophf 2017-04-23 13:54:20 +03:00
parent ceed8b565c
commit fdc15d24d9
3 changed files with 16 additions and 10 deletions

View File

@ -16,6 +16,7 @@ globals:
URLS: false
BG: false
notifyAllTabs: false
getTab: false
getActiveTab: false
getActiveTabRealURL: false
getTabRealURL: false

View File

@ -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});
});
});
}
}

View File

@ -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 =>