From 6fa6982e8ef8c07dda9362c6e15ac1b5d2695929 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 11 Oct 2015 17:09:49 +0300 Subject: [PATCH] Check if the tab is closed when trying to set its icon --- messaging.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/messaging.js b/messaging.js index 1d2c9eb6..0678f0db 100644 --- a/messaging.js +++ b/messaging.js @@ -49,10 +49,15 @@ function updateIcon(tab, styles) { chrome.browserAction.setIcon({ path: {19: "19" + postfix + ".png", 38: "38" + postfix + ".png"}, tabId: tab.id + }, function() { + // if the tab was just closed an error may occur, + // e.g. 'windowPosition' pref updated in edit.js::window.onbeforeunload + if (!chrome.runtime.lastError) { + var t = prefs.get("show-badge") && styles.length ? ("" + styles.length) : ""; + chrome.browserAction.setBadgeText({text: t, tabId: tab.id}); + chrome.browserAction.setBadgeBackgroundColor({color: disableAll ? "#aaa" : [0, 0, 0, 0]}); + } }); - var t = prefs.get("show-badge") && styles.length ? ("" + styles.length) : ""; - chrome.browserAction.setBadgeText({text: t, tabId: tab.id}); - chrome.browserAction.setBadgeBackgroundColor({color: disableAll ? "#aaa" : [0, 0, 0, 0]}); //console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'."); } }