mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
this fixes 207, re. "No tab with id: ..."
This commit is contained in:
parent
6ab9aac90f
commit
0b64dbf373
18
js/async.js
18
js/async.js
@ -137,16 +137,26 @@ return asyncJobManager;
|
||||
if ( tabId < 0 ) {
|
||||
return;
|
||||
}
|
||||
var updateBadgeCallback = function(tabId) {
|
||||
var pageStore = µBlock.pageStoreFromTabId(tabId);
|
||||
var safeUpdateBagde = function(tab) {
|
||||
if ( chrome.runtime.lastError ) {
|
||||
return;
|
||||
}
|
||||
var pageStore = µBlock.pageStoreFromTabId(tab.id);
|
||||
if ( pageStore ) {
|
||||
pageStore.updateBadge();
|
||||
} else {
|
||||
chrome.browserAction.setIcon({
|
||||
tabId: tabId,
|
||||
tabId: tab.id,
|
||||
path: { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' }
|
||||
});
|
||||
}
|
||||
};
|
||||
this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadgeCallback, 250);
|
||||
// https://github.com/gorhill/uBlock/issues/19
|
||||
// https://github.com/gorhill/uBlock/issues/207
|
||||
// Since we may be called asynchronously, the tab id may not exist
|
||||
// anymore, so this ensures it does still exist.
|
||||
var unsafeUpdateBadge = function(tabId) {
|
||||
chrome.tabs.get(tabId, safeUpdateBagde);
|
||||
};
|
||||
this.asyncJobs.add('updateBadge-' + tabId, tabId, unsafeUpdateBadge, 250);
|
||||
};
|
||||
|
@ -211,35 +211,25 @@ PageStore.prototype.recordRequest = function(type, url, reason) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
PageStore.prototype.updateBadgeFromTab = function(tab) {
|
||||
if ( !tab ) {
|
||||
return;
|
||||
}
|
||||
PageStore.prototype.updateBadge = function() {
|
||||
var netFiltering = this.getNetFilteringSwitch();
|
||||
var iconPath = netFiltering ?
|
||||
{ '19': 'img/browsericons/icon19.png', '38': 'img/browsericons/icon38.png' } :
|
||||
{ '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' };
|
||||
|
||||
chrome.browserAction.setIcon({ tabId: tab.id, path: iconPath });
|
||||
chrome.browserAction.setIcon({ tabId: this.tabId, path: iconPath });
|
||||
|
||||
var iconStr = '';
|
||||
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
|
||||
iconStr = µb.utils.formatCount(this.perLoadBlockedRequestCount);
|
||||
}
|
||||
chrome.browserAction.setBadgeText({ tabId: tab.id, text: iconStr });
|
||||
chrome.browserAction.setBadgeText({ tabId: this.tabId, text: iconStr });
|
||||
|
||||
if ( iconStr !== '' ) {
|
||||
chrome.browserAction.setBadgeBackgroundColor({ tabId: tab.id, color: '#666' });
|
||||
chrome.browserAction.setBadgeBackgroundColor({ tabId: this.tabId, color: '#666' });
|
||||
}
|
||||
};
|
||||
|
||||
PageStore.prototype.updateBadge = function() {
|
||||
// https://github.com/gorhill/uBlock/issues/19
|
||||
// Since we may be called asynchronously, the tab id may not exist
|
||||
// anymore, so this ensures it does still exist.
|
||||
chrome.tabs.get(this.tabId, this.updateBadgeFromTab.bind(this));
|
||||
};
|
||||
|
||||
// https://www.youtube.com/watch?v=drW8p_dTLD4
|
||||
|
||||
/******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user