From 36b1eac88e8afb9ee2b10f7c6088ee50d48dc6fc Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 10 Jan 2018 17:59:07 -0500 Subject: [PATCH] fix #3425 (regression from 6cdb20df) --- platform/chromium/vapi-background.js | 15 ++++++++------- src/js/messaging.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index b32e8af9a..21c3dbcfb 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -390,14 +390,15 @@ vAPI.tabs.registerListeners = function() { vAPI.tabs.get = function(tabId, callback) { if ( tabId === null ) { - chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { - if ( chrome.runtime.lastError ) { /* noop */ } - var tab = tabs && tabs[0]; - if ( tab ) { - tab.id = tab.id.toString(); + chrome.tabs.query( + { active: true, currentWindow: true }, + function(tabs) { + if ( chrome.runtime.lastError ) { /* noop */ } + callback( + Array.isArray(tabs) && tabs.length !== 0 ? tabs[0] : null + ); } - callback(tab); - }); + ); return; } diff --git a/src/js/messaging.js b/src/js/messaging.js index 73801ffc9..7ce4476c6 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1015,7 +1015,7 @@ var µb = µBlock, /******************************************************************************/ -var getLoggerData = function(ownerId, tab, callback) { +var getLoggerData = function(ownerId, activeTabId, callback) { var tabIds = {}; for ( var tabId in µb.pageStores ) { var pageStore = µb.pageStoreFromTabId(tabId); @@ -1023,9 +1023,8 @@ var getLoggerData = function(ownerId, tab, callback) { if ( pageStore.rawURL.startsWith(extensionPageURL) ) { continue; } tabIds[tabId] = pageStore.title; } - var activeTabId; - if ( tabIds.hasOwnProperty(tab.id) ) { - activeTabId = tab.id; + if ( activeTabId && tabIds.hasOwnProperty(activeTabId) === false ) { + activeTabId = undefined; } callback({ colorBlind: µb.userSettings.colorBlindFriendly, @@ -1083,7 +1082,11 @@ var onMessage = function(request, sender, callback) { return; } vAPI.tabs.get(null, function(tab) { - getLoggerData(request.ownerId, tab, callback); + getLoggerData( + request.ownerId, + tab && tab.id.toString(), + callback + ); }); return;