diff --git a/src/js/webrequest.js b/src/js/webrequest.js index c897ea7f30..f0a107be7c 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -529,6 +529,8 @@ function _isTabAnExtension(tabId) { /** * Provides the widget replacing content script with list of widgets to replace. * + * @param {Integer} tab_id the ID of the tab we're replacing widgets in + * * @returns {Object} dict containing the complete list of widgets * as well as a mapping to indicate which ones should be replaced */ @@ -544,7 +546,7 @@ let getWidgetBlockList = (function () { { key: "allow_once" }, ]; - return function () { + return function (tab_id) { // A mapping of individual SocialWidget objects to boolean values that determine // whether the content script should replace that tracker's button/widget var widgetsToReplace = {}; @@ -559,15 +561,23 @@ let getWidgetBlockList = (function () { } badger.widgetList.forEach(function (widget) { - // replace blocked widgets only - // and only if the widget is not on the 'do not replace' list - const replace = !badger.getSettings().getItem('widgetReplacementExceptions').includes(widget.name); - const action = badger.storage.getBestAction(widget.domain); - - widgetsToReplace[widget.name] = replace && ( - action == constants.BLOCK || - action == constants.USER_BLOCK - ); + // replace only if the widget is not on the 'do not replace' list + let replace = !badger.getSettings().getItem('widgetReplacementExceptions').includes(widget.name); + + // and only if it was blocked + if (replace && + badger.tabData.hasOwnProperty(tab_id) && + badger.tabData[tab_id].origins.hasOwnProperty(widget.domain)) { + + const action = badger.tabData[tab_id].origins[widget.domain]; + + replace = ( + action == constants.BLOCK || + action == constants.USER_BLOCK + ); + } + + widgetsToReplace[widget.name] = replace; }); return { @@ -679,7 +689,7 @@ function dispatcher(request, sender, sendResponse) { case "checkReplaceButton": { if (badger.isPrivacyBadgerEnabled(window.extractHostFromURL(sender.tab.url)) && badger.isWidgetReplacementEnabled()) { - let widgetBlockList = getWidgetBlockList(); + let widgetBlockList = getWidgetBlockList(sender.tab.id); sendResponse(widgetBlockList); }