Skip to content

Commit ad1265d

Browse files
pass along replaced widgets info to popup and append to expandable section
1 parent 90abda2 commit ad1265d

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/js/popup.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,13 @@ function refreshPopup() {
738738

739739
// if there are replaced widgets, get their names and append to that popup section
740740
if (Object.keys(POPUP_DATA.replacedWidgets).length) {
741-
let name = POPUP_DATA.replacedWidgets.name;
742-
// prevent duplicate names from appearing, only append if it doesn't already exist
743-
if (!$('#instructions-widgets-description li:contains("' + name + '")').length) {
744-
$("#instructions-widgets-description").append("<li>" + name + "</li>");
741+
for (let widget in POPUP_DATA.replacedWidgets) {
742+
POPUP_DATA.replacedWidgets[widget].forEach((widgetType) => {
743+
// prevent duplicate names from appearing, only append if it doesn't already exist
744+
if (!$('#instructions-widgets-description li:contains("' + widgetType + '")').length) {
745+
$("#instructions-widgets-description").append("<li>" + widgetType + "</li>");
746+
}
747+
});
745748
}
746749
}
747750

src/js/webrequest.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ let constants = require("constants"),
3434

3535
/************ Local Variables *****************/
3636
let tempAllowlist = {},
37-
tempAllowedWidgets = {};
37+
tempAllowedWidgets = {},
38+
replacedWidgets = {};
3839

3940
/***************** Blocking Listener Functions **************/
4041

@@ -882,6 +883,7 @@ function dispatcher(request, sender, sendResponse) {
882883
"getBlockedFrameUrls",
883884
"getReplacementButton",
884885
"inspectLocalStorage",
886+
"sendReplacedWidgetsToPopup",
885887
"supercookieReport",
886888
"unblockWidget",
887889
];
@@ -1062,6 +1064,25 @@ function dispatcher(request, sender, sendResponse) {
10621064
break;
10631065
}
10641066

1067+
case "sendReplacedWidgetsToPopup": {
1068+
let tab_host;
1069+
// iframes send unreliable host responses, sender url and falsey frameId is to get top-level host
1070+
if (sender.frameId == 0 && sender.url) {
1071+
tab_host = sender.url;
1072+
}
1073+
1074+
// avoid setting undefined properties on local replaced widgets array, but establish a property for known host
1075+
if (!replacedWidgets[tab_host] && tab_host) {
1076+
replacedWidgets[tab_host] = [];
1077+
}
1078+
1079+
// only save widget name if it's not already present in local widgets array
1080+
if (!replacedWidgets[tab_host].includes(request.widgetName)) {
1081+
replacedWidgets[tab_host].push(request.widgetName);
1082+
}
1083+
break;
1084+
}
1085+
10651086
case "getPopupData": {
10661087
let tab_id = request.tabId;
10671088

@@ -1085,6 +1106,13 @@ function dispatcher(request, sender, sendResponse) {
10851106
}
10861107
}
10871108

1109+
// before sending response, remove old replaced widgets information from previous tabs
1110+
for (let host in replacedWidgets) {
1111+
if (!host.includes(tab_host)) {
1112+
delete replacedWidgets[host];
1113+
}
1114+
}
1115+
10881116
sendResponse({
10891117
cookieblocked,
10901118
criticalError: badger.criticalError,
@@ -1093,6 +1121,7 @@ function dispatcher(request, sender, sendResponse) {
10931121
isOnFirstParty: utils.firstPartyProtectionsEnabled(tab_host),
10941122
noTabData: false,
10951123
origins,
1124+
replacedWidgets: replacedWidgets,
10961125
settings: badger.getSettings().getItemClones(),
10971126
showLearningPrompt: badger.getPrivateSettings().getItem("showLearningPrompt"),
10981127
showWebRtcDeprecation: !!badger.getPrivateSettings().getItem("showWebRtcDeprecation"),

0 commit comments

Comments
 (0)