mirror of https://github.com/gorhill/uBlock.git
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 ) {
|
if ( tabId < 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var updateBadgeCallback = function(tabId) {
|
var safeUpdateBagde = function(tab) {
|
||||||
var pageStore = µBlock.pageStoreFromTabId(tabId);
|
if ( chrome.runtime.lastError ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pageStore = µBlock.pageStoreFromTabId(tab.id);
|
||||||
if ( pageStore ) {
|
if ( pageStore ) {
|
||||||
pageStore.updateBadge();
|
pageStore.updateBadge();
|
||||||
} else {
|
} else {
|
||||||
chrome.browserAction.setIcon({
|
chrome.browserAction.setIcon({
|
||||||
tabId: tabId,
|
tabId: tab.id,
|
||||||
path: { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' }
|
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) {
|
PageStore.prototype.updateBadge = function() {
|
||||||
if ( !tab ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var netFiltering = this.getNetFilteringSwitch();
|
var netFiltering = this.getNetFilteringSwitch();
|
||||||
var iconPath = netFiltering ?
|
var iconPath = netFiltering ?
|
||||||
{ '19': 'img/browsericons/icon19.png', '38': 'img/browsericons/icon38.png' } :
|
{ '19': 'img/browsericons/icon19.png', '38': 'img/browsericons/icon38.png' } :
|
||||||
{ '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.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 = '';
|
var iconStr = '';
|
||||||
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
|
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
|
||||||
iconStr = µb.utils.formatCount(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 !== '' ) {
|
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
|
// https://www.youtube.com/watch?v=drW8p_dTLD4
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue