From 29bbeb80bb7014e12b41ff9fc7196621b2e2031a Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sun, 25 Feb 2024 15:33:28 -0500 Subject: [PATCH 01/17] initial changes (Issue #350) --- src/background/protection/protection-ff.js | 8 +++++--- src/manifests/firefox/manifest-dev.json | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/background/protection/protection-ff.js b/src/background/protection/protection-ff.js index 84e5a82..56f878a 100644 --- a/src/background/protection/protection-ff.js +++ b/src/background/protection/protection-ff.js @@ -69,7 +69,7 @@ const listenerCallbacks = { onBeforeSendHeaders: async (details) => { await updateDomainlist(details); - if (sendSignal) { + if (true) { signalPerTab[details.tabId] = true; return addHeaders(details); } @@ -100,7 +100,7 @@ const listenerCallbacks = { */ onCommitted: async (details) => { initIAB(sendSignal); - if (sendSignal) { + if (true) { addDomSignal(details); updatePopupIcon(details); } @@ -119,6 +119,7 @@ const listenerCallbacks = { * @returns {array} details.requestHeaders */ function addHeaders(details) { + console.log("addHeaders called"); for (let signal in headers) { let s = headers[signal]; details.requestHeaders.push({ name: s.name, value: s.value }); @@ -131,7 +132,8 @@ function addHeaders(details) { * @param {object} details - retrieved info passed into callback */ function addDomSignal(details) { - chrome.tabs.executeScript(details.tabId, { + console.log("addDomSignal called"); + chrome.scripting.executeScript(details.tabId, { file: "../../content-scripts/injection/gpc-dom.js", frameId: details.frameId, // Supposed to solve multiple injections // as opposed to allFrames: true diff --git a/src/manifests/firefox/manifest-dev.json b/src/manifests/firefox/manifest-dev.json index 7e9fae7..a15216b 100644 --- a/src/manifests/firefox/manifest-dev.json +++ b/src/manifests/firefox/manifest-dev.json @@ -4,19 +4,22 @@ "version": "4.3.1", "description": "OptMeowt allows Web users to make use of their rights to opt out from the sale and sharing of personal data", "permissions": [ - "", "webRequestBlocking", "webRequest", "webNavigation", "storage", "activeTab", "cookies", - "tabs" + "tabs", + "scripting" + ], + "host_permissions": [ + "" ], "icons": { "128": "assets/face-icons/icon128-face-circle.png" }, - "browser_action": { + "action": { "default_title": "OptMeowt", "default_popup": "popup.html" }, @@ -35,9 +38,15 @@ "scripts": ["background.bundle.js"] }, "web_accessible_resources": [ - "json/*.json" ], - "manifest_version": 2, + "manifest_version": 3, "incognito": "spanning", - "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" + "content_security_policy": { + "extension_pages": "script-src 'self'; object-src 'self'" + }, + "browser_specific_settings": { + "gecko": { + "id": "{7f22397f-fb61-47e2-9e4b-4ddd98faa275}" + } + } } From 2fd241fa5aef476eea9eac203e9d70884bb99798 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Wed, 28 Feb 2024 11:58:05 -0500 Subject: [PATCH 02/17] Experimenting with headers (Issue #350) --- src/background/protection/protection-ff.js | 7 +++++++ src/content-scripts/contentScript.js | 2 ++ src/manifests/firefox/manifest-dev.json | 21 +++++++++++++++++++-- src/rules/gpc_exceptions_rules.json | 2 -- src/rules/universal_gpc_rules.json | 2 -- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/background/protection/protection-ff.js b/src/background/protection/protection-ff.js index 56f878a..d907730 100644 --- a/src/background/protection/protection-ff.js +++ b/src/background/protection/protection-ff.js @@ -48,6 +48,13 @@ async function reloadVars() { reloadVars(); +chrome.declarativeNetRequest.getEnabledRulesets().then( + (rules) => { + console.log("Dynamic rules:"); + console.log(rules); + } +); + /******************************************************************************/ /******************************************************************************/ /********** # Lisetener callbacks - Main functionality **********/ diff --git a/src/content-scripts/contentScript.js b/src/content-scripts/contentScript.js index 398d7ef..f090888 100644 --- a/src/content-scripts/contentScript.js +++ b/src/content-scripts/contentScript.js @@ -20,6 +20,8 @@ https://developer.chrome.com/extensions/content_scripts /******************************************************************************/ /******************************************************************************/ +console.log("contentScript.js ran"); + // To be injected to call the USPAPI function in analysis mode const uspapi = ` try { diff --git a/src/manifests/firefox/manifest-dev.json b/src/manifests/firefox/manifest-dev.json index a15216b..2a49a84 100644 --- a/src/manifests/firefox/manifest-dev.json +++ b/src/manifests/firefox/manifest-dev.json @@ -5,6 +5,7 @@ "description": "OptMeowt allows Web users to make use of their rights to opt out from the sale and sharing of personal data", "permissions": [ "webRequestBlocking", + "declarativeNetRequest", "webRequest", "webNavigation", "storage", @@ -13,6 +14,20 @@ "tabs", "scripting" ], + "declarative_net_request": { + "rule_resources": [ + { + "id": "universal_GPC", + "enabled": true, + "path": "rules/universal_gpc_rules.json" + }, + { + "id": "GPC_exceptions", + "enabled": true, + "path": "rules/gpc_exceptions_rules.json" + } + ] + }, "host_permissions": [ "" ], @@ -37,8 +52,10 @@ "background": { "scripts": ["background.bundle.js"] }, - "web_accessible_resources": [ - ], + "web_accessible_resources": [{ + "resources": ["content-scripts/injection/gpc-dom.js"], + "matches": [""] + }], "manifest_version": 3, "incognito": "spanning", "content_security_policy": { diff --git a/src/rules/gpc_exceptions_rules.json b/src/rules/gpc_exceptions_rules.json index 58f7dee..73579d8 100644 --- a/src/rules/gpc_exceptions_rules.json +++ b/src/rules/gpc_exceptions_rules.json @@ -25,8 +25,6 @@ "csp_report", "media", "websocket", - "webtransport", - "webbundle", "other" ] } diff --git a/src/rules/universal_gpc_rules.json b/src/rules/universal_gpc_rules.json index 9082781..f408c36 100644 --- a/src/rules/universal_gpc_rules.json +++ b/src/rules/universal_gpc_rules.json @@ -25,8 +25,6 @@ "csp_report", "media", "websocket", - "webtransport", - "webbundle", "other" ] } From 2626a56a37208f861cbf2850ba8945c9e2e7368c Mon Sep 17 00:00:00 2001 From: Mattm27 Date: Sun, 24 Mar 2024 19:43:18 -0400 Subject: [PATCH 03/17] Host permission handler --- src/background/control.js | 26 ++++++++++++++++++++++++++ src/popup/popup.html | 4 +++- src/popup/popup.js | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/background/control.js b/src/background/control.js index f3c8c0b..159709f 100644 --- a/src/background/control.js +++ b/src/background/control.js @@ -61,6 +61,32 @@ function disable() { } ]); } + // Check if the browser is Firefox +if (typeof browser !== 'undefined') { + async function requestPermissions() { + try { + // Request permissions + const response = await browser.permissions.request({ + origins: [""] // Allows host permissions + }); + + // Check if permissions were granted or refused + if (response) { + console.log("Permissions were granted"); + } else { + console.log("Permissions were refused"); + } + + // Retrieve current permissions after the request + const currentPermissions = await browser.permissions.getAll(); + console.log(`Current permissions:`, currentPermissions); + } catch (error) { + console.error('Error requesting permissions:', error); + } + } + // Call the function to open the onboarding tab and request permissions + requestPermissions(); + } // Initializes the default settings let settingsDB = await storage.getStore(stores.settings); for (let setting in defaultSettings) { diff --git a/src/popup/popup.html b/src/popup/popup.html index 4f4bd18..f93cdae 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -234,7 +234,9 @@
- + + +
{ await storage.set(stores.settings, true, "DOMAINLIST_PRESSED"); chrome.runtime.openOptionsPage(); }); + +document.addEventListener('DOMContentLoaded', function () { + const requestPermissionsButton = document.getElementById('requestPermissionsButton'); + requestPermissionsButton.addEventListener('click', requestPermissions); +}); + +async function requestPermissions() { + try { + // Request permissions + const response = await browser.permissions.request({ + origins: [""] // Allows host permissions + }); + + // Check if permissions were granted or refused + if (response) { + console.log("Permissions were granted"); + } else { + console.log("Permissions were refused"); + } + + // Retrieve current permissions after the request + const currentPermissions = await browser.permissions.getAll(); + console.log(`Current permissions:`, currentPermissions); + } catch (error) { + console.error('Error requesting permissions:', error); + } +} From a7b2082a025267ba0f9a53b6afdaa1ee5f260ef6 Mon Sep 17 00:00:00 2001 From: Mattm27 Date: Sun, 24 Mar 2024 20:16:37 -0400 Subject: [PATCH 04/17] Popup message upon installation added --- src/background/control.js | 28 +++---------- src/data/defaultSettings.js | 1 + .../views/settings-view/settings-view.html | 16 ++++++++ .../views/settings-view/settings-view.js | 39 +++++++++++++++++++ src/popup/popup.html | 3 -- src/popup/popup.js | 27 ------------- 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/background/control.js b/src/background/control.js index 159709f..e622dd6 100644 --- a/src/background/control.js +++ b/src/background/control.js @@ -62,30 +62,12 @@ function disable() { ]); } // Check if the browser is Firefox -if (typeof browser !== 'undefined') { - async function requestPermissions() { - try { - // Request permissions - const response = await browser.permissions.request({ - origins: [""] // Allows host permissions - }); - - // Check if permissions were granted or refused - if (response) { - console.log("Permissions were granted"); - } else { - console.log("Permissions were refused"); - } - - // Retrieve current permissions after the request - const currentPermissions = await browser.permissions.getAll(); - console.log(`Current permissions:`, currentPermissions); - } catch (error) { - console.error('Error requesting permissions:', error); +if ("$BROWSER" == "firefox") { + chrome.runtime.onInstalled.addListener(function (details) { + if (details.reason === 'install') { + chrome.runtime.openOptionsPage((result) => {}); } - } - // Call the function to open the onboarding tab and request permissions - requestPermissions(); + }); } // Initializes the default settings let settingsDB = await storage.getStore(stores.settings); diff --git a/src/data/defaultSettings.js b/src/data/defaultSettings.js index 3cae0a4..5d70190 100644 --- a/src/data/defaultSettings.js +++ b/src/data/defaultSettings.js @@ -15,5 +15,6 @@ export const defaultSettings = { IS_DOMAINLISTED: false, IS_ENABLED: true, TUTORIAL_SHOWN: true, + REQUEST_PERMISSIONS_SHOWN: false, TUTORIAL_SHOWN_IN_POPUP: true, }; diff --git a/src/options/views/settings-view/settings-view.html b/src/options/views/settings-view/settings-view.html index 0c45805..57885f6 100644 --- a/src/options/views/settings-view/settings-view.html +++ b/src/options/views/settings-view/settings-view.html @@ -34,6 +34,22 @@

Welcome to OptMeowt!

+
+
+ +
+ +

Welcome to OptMeowt!

+
+
+ OptMeowt requires host permissions to be enabled to work correclty. Please enable these permissions using the button below. +
+ +
+
+
diff --git a/src/options/views/settings-view/settings-view.js b/src/options/views/settings-view/settings-view.js index 9736048..f927ab6 100644 --- a/src/options/views/settings-view/settings-view.js +++ b/src/options/views/settings-view/settings-view.js @@ -220,6 +220,7 @@ async function requestPermissionsButton() { // Check if permissions were granted or refused if (response) { console.log("Permissions were granted"); + storage.set(stores.settings, true, "REQUEST_PERMISSIONS_SHOWN"); } else { console.log("Permissions were refused"); } @@ -237,6 +238,7 @@ function requestPermissions() { modal.show(); document.getElementById("modal-button-4").onclick = () => { requestPermissionsButton(); + modal.hide(); } } @@ -282,5 +284,4 @@ export async function settingsView(scaffoldTemplate) { if (!requestShown) { requestPermissions(); } - storage.set(stores.settings, true, "REQUEST_PERMISSIONS_SHOWN"); }} From 84b0205e279ef1689ce0f7e8035de91e6d797329 Mon Sep 17 00:00:00 2001 From: Mattm27 Date: Thu, 28 Mar 2024 22:32:37 -0400 Subject: [PATCH 07/17] DOM signal implementation added for MV3 --- src/background/control.js | 21 +++++-------------- src/background/protection/protection-ff.js | 1 - src/background/protection/protection.js | 3 --- src/background/storage.js | 3 --- src/common/editDomainlist.js | 16 ++------------ src/common/editRules.js | 4 ---- .../views/domainlist-view/domainlist-view.js | 6 ------ .../views/settings-view/settings-view.js | 6 ------ src/popup/popup.js | 4 ---- 9 files changed, 7 insertions(+), 57 deletions(-) diff --git a/src/background/control.js b/src/background/control.js index e622dd6..638704f 100644 --- a/src/background/control.js +++ b/src/background/control.js @@ -28,20 +28,12 @@ import { } from "../common/editDomainlist.js"; async function enable() { - if ("$BROWSER" == "firefox") { - var initProtection = initProtection_ff; - } else { - var initProtection = initProtection_cr; - } + var initProtection = initProtection_cr; initProtection(); } function disable() { - if ("$BROWSER" == "firefox") { - var haltProtection = haltProtection_ff; - } else if ("$BROWSER" == "chrome") { - var haltProtection = haltProtection_cr; - } + var haltProtection = haltProtection_cr; haltProtection(); } @@ -50,7 +42,6 @@ function disable() { // This is the very first thing the extension runs (async () => { - if ("$BROWSER" == "chrome") { chrome.scripting.registerContentScripts([ { id: "1", @@ -60,7 +51,7 @@ function disable() { runAt: "document_start", } ]); - } + // Check if the browser is Firefox if ("$BROWSER" == "firefox") { chrome.runtime.onInstalled.addListener(function (details) { @@ -82,10 +73,8 @@ if ("$BROWSER" == "firefox") { if (isEnabled) { // Turns on the extension enable(); - if ("$BROWSER" == "chrome") { - updateRemovalScript(); - reloadDynamicRules(); - } + updateRemovalScript(); + reloadDynamicRules(); } })(); diff --git a/src/background/protection/protection-ff.js b/src/background/protection/protection-ff.js index d907730..8b5e110 100644 --- a/src/background/protection/protection-ff.js +++ b/src/background/protection/protection-ff.js @@ -32,7 +32,6 @@ var wellknown = {}; // Caches wellknown info to be sent to popup var signalPerTab = {}; // Caches if a signal is sent to render the popup icon var activeTabID = 0; // Caches current active tab id var sendSignal = true; // Caches if the signal can be sent to the curr domain -var isFirefox = ("$BROWSER" === "firefox"); var domPrev3rdParties = {}; //stores all the 3rd parties by domain (resets when you quit chrome) var globalParsedDomain; diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index c7117bc..763d6e6 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -38,11 +38,8 @@ var signalPerTab = {}; // Caches if a signal is sent to render the popup icon var activeTabID = 0; // Caches current active tab id var sendSignal = true; // Caches if the signal can be sent to the curr domain var domPrev3rdParties = {}; //stores all the 3rd parties by domain (resets when you quit chrome) -var isFirefox = ("$BROWSER" === "firefox"); var globalParsedDomain; -var isFirefox = "$BROWSER" === "firefox"; - async function reloadVars() { let storedDomainlisted = await storage.get( stores.settings, diff --git a/src/background/storage.js b/src/background/storage.js index 95a3734..8c42835 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -97,9 +97,6 @@ const storage = { async function handleDownload() { const DOMAINLIST = await storage.getStore(stores.domainlist); let MANIFEST = chrome.runtime.getManifest(); - if ("$BROWSER" == "firefox") { - MANIFEST.version = "2.0"; - } let data = { VERSION: MANIFEST.version, DOMAINLIST: DOMAINLIST, diff --git a/src/common/editDomainlist.js b/src/common/editDomainlist.js index ac9f3d5..1fe07bd 100644 --- a/src/common/editDomainlist.js +++ b/src/common/editDomainlist.js @@ -29,7 +29,6 @@ import { /******************************************************************************/ async function updateRemovalScript() { - if ("$BROWSER" == "chrome") { let ex_matches = ["https://example.org/foo/bar.html"]; let domain; let domainValue; @@ -55,10 +54,8 @@ async function updateRemovalScript() { ]) .then(() => {}); } -} async function createCS(domain){ - if ("$BROWSER" == "chrome") { let script = await chrome.scripting.getRegisteredContentScripts({ }); @@ -78,10 +75,8 @@ async function createCS(domain){ ]) .then(() => {}); } -} async function deleteCS(domain){ - if ("$BROWSER" == "chrome") { let script = await chrome.scripting.getRegisteredContentScripts({ }); let ex_matches = script[0].excludeMatches; @@ -106,33 +101,26 @@ async function deleteCS(domain){ ]) .then(() => {}); } -} async function deleteDomainlistAndDynamicRules() { await storage.clear(stores.domainlist); - if ("$BROWSER" == "chrome") { deleteAllDynamicRules(); } -} async function addDomainToDomainlistAndRules(domain) { let id = 1; - if ("$BROWSER" == "chrome") { id = await getFreshId(); addDynamicRule(id, domain); // add the rule for the chosen domain createCS(domain); - } - await storage.set(stores.domainlist, id, domain); // record what rule the domain is associated to + await storage.set(stores.domainlist, id, domain); // record what rule the domain is associated to } async function removeDomainFromDomainlistAndRules(domain) { - if ("$BROWSER" == "chrome") { let id = await storage.get(stores.domainlist, domain); deleteDynamicRule(id); deleteCS(domain); + await storage.set(stores.domainlist, null, domain); } - await storage.set(stores.domainlist, null, domain); -} /******************************************************************************/ /******************************************************************************/ diff --git a/src/common/editRules.js b/src/common/editRules.js index 8d69a61..48e3080 100644 --- a/src/common/editRules.js +++ b/src/common/editRules.js @@ -101,8 +101,6 @@ export async function addDynamicRule(id, domain) { "csp_report", "media", "websocket", - "webtransport", - "webbundle", "other", ], }, @@ -121,7 +119,6 @@ export async function addDynamicRule(id, domain) { * receiving GPC or other opt-outs. */ export async function reloadDynamicRules() { - if ("$BROWSER" == "chrome") { deleteAllDynamicRules(); let domainlist = await storage.getStore(stores.domainlist); @@ -138,4 +135,3 @@ export async function reloadDynamicRules() { ); }); } -} diff --git a/src/options/views/domainlist-view/domainlist-view.js b/src/options/views/domainlist-view/domainlist-view.js index 3f462fc..0b24249 100644 --- a/src/options/views/domainlist-view/domainlist-view.js +++ b/src/options/views/domainlist-view/domainlist-view.js @@ -93,12 +93,6 @@ function deleteButtonListener(domain) { NOTE: It will be automatically added back to the list when the domain is requested again.`; if (confirm(deletePrompt)) { await storage.delete(stores.domainlist, domain); - if ("$BROWSER" == "firefox") { - chrome.runtime.sendMessage({ - msg: "REMOVE_FROM_DOMAINLIST", - data: domain, - }); - } reloadDynamicRules(); updateRemovalScript(); diff --git a/src/options/views/settings-view/settings-view.js b/src/options/views/settings-view/settings-view.js index f927ab6..487fabf 100644 --- a/src/options/views/settings-view/settings-view.js +++ b/src/options/views/settings-view/settings-view.js @@ -59,7 +59,6 @@ function eventListeners() { msg: "CHANGE_IS_DOMAINLISTED", data: { isDomainlisted: false }, }); - if ("$BROWSER" == "chrome") { chrome.scripting.updateContentScripts([ { id: "1", @@ -70,7 +69,6 @@ function eventListeners() { }, ]); deleteAllDynamicRules(); - } }); document .getElementById("settings-view-radio1") @@ -83,7 +81,6 @@ function eventListeners() { msg: "CHANGE_IS_DOMAINLISTED", data: { isDomainlisted: false }, }); - if ("$BROWSER" == "chrome") { chrome.scripting.updateContentScripts([ { id: "1", @@ -94,7 +91,6 @@ function eventListeners() { }, ]); addDynamicRule(4999, "*"); - } }); document .getElementById("settings-view-radio2") @@ -107,10 +103,8 @@ function eventListeners() { msg: "CHANGE_IS_DOMAINLISTED", data: { isDomainlisted: true }, }); - if ("$BROWSER" == "chrome") { updateRemovalScript(); reloadDynamicRules(); - } }); document .getElementById("download-button") diff --git a/src/popup/popup.js b/src/popup/popup.js index d4bd061..018c128 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -138,7 +138,6 @@ function renderExtensionIsEnabledDisabled(isEnabled, isDomainlisted) { } function turnonoff(isEnabled) { - if ("$BROWSER" == "chrome") { if (isEnabled) { chrome.scripting.updateContentScripts([ { @@ -154,7 +153,6 @@ function turnonoff(isEnabled) { updateRemovalScript(); reloadDynamicRules(); } - } } function listenerExtensionIsEnabledDisabledButton( @@ -427,12 +425,10 @@ function showProtectionInfo() { data: null, }); - if ("$BROWSER" == "chrome") { chrome.runtime.sendMessage({ msg: "POPUP_PROTECTION_REQUESTS", data: null, }); - } } /** From ab05898cd45c7a37173a0e09d6b8496c2e75dd73 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sun, 7 Apr 2024 20:51:53 -0400 Subject: [PATCH 08/17] Fixed icon and well known data --- src/background/protection/protection.js | 8 +++++--- src/content-scripts/contentScript.js | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index 763d6e6..05d734b 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -295,7 +295,6 @@ function dataToPopupHelper(){ // Info back to popup function dataToPopup(wellknownData) { - let requestsData = dataToPopupHelper(); //get requests from the helper chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ let popupData = { @@ -392,7 +391,9 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { dataToPopupRequests(); } if (message.msg === "CONTENT_SCRIPT_WELLKNOWN") { - let url = new URL(sender.origin); + // sender.origin not working for Firefox MV3, instead added a new message argument, message.origin_url + //let url = new URL(sender.origin); + let url = new URL(message.origin_url); let parsed = psl.parse(url.hostname); let domain = parsed.domain; @@ -402,7 +403,9 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { wellknown[tabID] = message.data; let wellknownData = message.data; + initIAB(!sendSignal); + if (wellknown[tabID] === null && sendSignal == null) { updatePopupIcon(tabID); } else if (wellknown[tabID]["gpc"] === true && sendSignal == null) { @@ -451,7 +454,6 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { initCookiesPerDomain(message.data); } if (message.msg === "DELETE_OPTOUT_COOKIES") { - console.log("Msg received. Info; ", message.data); deleteCookiesPerDomain(message.data); } diff --git a/src/content-scripts/contentScript.js b/src/content-scripts/contentScript.js index f090888..e1a3856 100644 --- a/src/content-scripts/contentScript.js +++ b/src/content-scripts/contentScript.js @@ -20,7 +20,6 @@ https://developer.chrome.com/extensions/content_scripts /******************************************************************************/ /******************************************************************************/ -console.log("contentScript.js ran"); // To be injected to call the USPAPI function in analysis mode const uspapi = ` @@ -57,6 +56,7 @@ function injectScript(script) { async function getWellknown(url) { const response = await fetch(`${url.origin}/.well-known/gpc.json`); + new_url = url = JSON.parse(JSON.stringify(url)); let wellknownData; try { wellknownData = await response.json(); @@ -66,6 +66,7 @@ async function getWellknown(url) { chrome.runtime.sendMessage({ msg: "CONTENT_SCRIPT_WELLKNOWN", data: wellknownData, + origin_url: new_url }); } From c6b6f8ea773128cb8038981e0a6b2a519ce86b18 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Wed, 10 Apr 2024 15:27:04 -0400 Subject: [PATCH 09/17] some storage changes --- src/background/protection/protection.js | 27 +++++++++++++++++-------- src/background/storage.js | 2 ++ src/popup/popup.js | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index 05d734b..d3d085c 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -140,7 +140,7 @@ async function updateDomainlist(details) { let currDomainValue = await storage.get(stores.domainlist, parsedDomain); if (currDomainValue === undefined) { - storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async + await storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async } //get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable) @@ -155,6 +155,11 @@ async function updateDomainlist(details) { } //as they come in, add the parsedDomain to the object with null value (just a placeholder) domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; + + let data = JSON.stringify(domPrev3rdParties); + console.log("setting to storage: ", data); + await storage.set(stores.thirdParties, data, "parties"); + } function updatePopupIcon(tabId) { @@ -282,20 +287,25 @@ function handleSendMessageError() { console.warn(error.message); } } -function dataToPopupHelper(){ +async function dataToPopupHelper(){ //data gets sent back every time the popup is clicked let requestsData = {}; if (tabs[activeTabID] !== undefined) { - - requestsData = domPrev3rdParties[activeTabID][globalParsedDomain]; + let domain = await getCurrentParsedDomain(); + let parties = await storage.get(stores.thirdParties, "parties"); + parties = JSON.parse(parties); + console.log("parties: ", parties[activeTabID][domain]); + + requestsData = parties[activeTabID][domain]; + console.log("request data: ", requestsData); } return requestsData } // Info back to popup -function dataToPopup(wellknownData) { - let requestsData = dataToPopupHelper(); //get requests from the helper +async function dataToPopup(wellknownData) { + let requestsData = await dataToPopupHelper(); //get requests from the helper chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ let popupData = { requests: requestsData, @@ -312,9 +322,9 @@ function dataToPopup(wellknownData) { }); } -function dataToPopupRequests() { +async function dataToPopupRequests() { - let requestsData = dataToPopupHelper(); //get requests from the helper + let requestsData = await dataToPopupHelper(); //get requests from the helper chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.runtime.sendMessage( @@ -388,6 +398,7 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { storage.set(stores.domainlist, key, domain); // Sets to long term storage } if (message.msg === "POPUP_PROTECTION_REQUESTS") { + console.log("info queried"); dataToPopupRequests(); } if (message.msg === "CONTENT_SCRIPT_WELLKNOWN") { diff --git a/src/background/storage.js b/src/background/storage.js index 8c42835..4a8afcf 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -26,6 +26,7 @@ const { saveAs } = pkg; const stores = Object.freeze({ settings: "SETTINGS", domainlist: "DOMAINLIST", + thirdParties: "THIRDPARTIES", }); /******************************************************************************/ @@ -36,6 +37,7 @@ const dbPromise = openDB("extensionDB", 1, { upgrade: function dbPromiseInternal(db) { db.createObjectStore(stores.domainlist); db.createObjectStore(stores.settings); + db.createObjectStore(stores.thirdParties); }, }); diff --git a/src/popup/popup.js b/src/popup/popup.js index 018c128..9693c0f 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -657,6 +657,7 @@ async function buildWellKnown(requests) { chrome.runtime.onMessage.addListener(function (message, _, __) { if (message.msg === "POPUP_PROTECTION_DATA") { let { requests, wellknown } = message.data; + console.log("info received"); domainsInfo = requests; wellknownInfo = wellknown; buildDomains(requests); From ddc3c18a8f992349731943e43b76f05b509f6db0 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Mon, 15 Apr 2024 19:25:24 -0400 Subject: [PATCH 10/17] New popup storage method --- src/background/protection/protection-ff.js | 6 ----- src/background/protection/protection.js | 24 ++++++++++-------- src/popup/popup.js | 29 ++++++++++++++-------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/background/protection/protection-ff.js b/src/background/protection/protection-ff.js index 8b5e110..5ec2a32 100644 --- a/src/background/protection/protection-ff.js +++ b/src/background/protection/protection-ff.js @@ -47,12 +47,6 @@ async function reloadVars() { reloadVars(); -chrome.declarativeNetRequest.getEnabledRulesets().then( - (rules) => { - console.log("Dynamic rules:"); - console.log(rules); - } -); /******************************************************************************/ /******************************************************************************/ diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index d3d085c..98a1def 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -156,7 +156,7 @@ async function updateDomainlist(details) { //as they come in, add the parsedDomain to the object with null value (just a placeholder) domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; - let data = JSON.stringify(domPrev3rdParties); + let data = JSON.stringify(domPrev3rdParties[activeTabID]); console.log("setting to storage: ", data); await storage.set(stores.thirdParties, data, "parties"); @@ -289,22 +289,25 @@ function handleSendMessageError() { } async function dataToPopupHelper(){ //data gets sent back every time the popup is clicked - let requestsData = {}; + let requestsData = {}; + + console.log("data to popup helper called"); - if (tabs[activeTabID] !== undefined) { + //if (tabs[activeTabID] !== undefined) { let domain = await getCurrentParsedDomain(); let parties = await storage.get(stores.thirdParties, "parties"); parties = JSON.parse(parties); - console.log("parties: ", parties[activeTabID][domain]); + console.log("parties: ", parties[domain]); - requestsData = parties[activeTabID][domain]; + requestsData = parties[domain]; console.log("request data: ", requestsData); - } + //} return requestsData } // Info back to popup async function dataToPopup(wellknownData) { + console.log("datatopopup called"); let requestsData = await dataToPopupHelper(); //get requests from the helper chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ let popupData = { @@ -323,8 +326,9 @@ async function dataToPopup(wellknownData) { } async function dataToPopupRequests() { - + console.log("datatopopuprequests called"); let requestsData = await dataToPopupHelper(); //get requests from the helper + console.log("requests data in DTPR: ", requestsData) chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.runtime.sendMessage( @@ -399,7 +403,7 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { } if (message.msg === "POPUP_PROTECTION_REQUESTS") { console.log("info queried"); - dataToPopupRequests(); + await dataToPopupRequests(); } if (message.msg === "CONTENT_SCRIPT_WELLKNOWN") { // sender.origin not working for Firefox MV3, instead added a new message argument, message.origin_url @@ -425,9 +429,9 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { path: "assets/face-icons/optmeow-face-circle-green-128.png", }); } - chrome.runtime.onMessage.addListener(function (message, _, __) { + chrome.runtime.onMessage.addListener(async function (message, _, __) { if (message.msg === "POPUP_PROTECTION") { - dataToPopup(wellknownData); + await dataToPopup(wellknownData); } }); } diff --git a/src/popup/popup.js b/src/popup/popup.js index 9693c0f..7412b83 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -393,7 +393,7 @@ function removeListenerDropdown2Toggle() { /** * Redraws the popup for protection mode */ -function showProtectionInfo() { +async function showProtectionInfo() { removeFirstPartyDomainDNSToggle(); removeListenerDropdown1Toggle(); removeListenerDropdown2Toggle(); @@ -420,15 +420,20 @@ function showProtectionInfo() { listenerDropdown1Toggle(); listenerDropdown2Toggle(); - chrome.runtime.sendMessage({ - msg: "POPUP_PROTECTION", - data: null, - }); - - chrome.runtime.sendMessage({ - msg: "POPUP_PROTECTION_REQUESTS", - data: null, - }); + let domain = await getCurrentParsedDomain(); + let parties = await storage.get(stores.thirdParties, "parties"); + parties = JSON.parse(parties); + console.log("parties: ", parties[domain]); + + let requestsData = parties[domain]; + console.log("request data: ", requestsData); + buildDomains(requestsData); + + + // chrome.runtime.sendMessage({ + // msg: "POPUP_PROTECTION_REQUESTS", + // data: null, + // }); } /** @@ -657,14 +662,16 @@ async function buildWellKnown(requests) { chrome.runtime.onMessage.addListener(function (message, _, __) { if (message.msg === "POPUP_PROTECTION_DATA") { let { requests, wellknown } = message.data; - console.log("info received"); + console.log("info received PPD"); domainsInfo = requests; wellknownInfo = wellknown; buildDomains(requests); buildWellKnown(wellknown); } if (message.msg === "POPUP_PROTECTION_DATA_REQUESTS") { + console.log("info received PPDR"); let requests = message.data; + console.log("requests: ", requests); buildDomains(requests); } }); From 566630e37b1807de33b4b98a3770ec420292272b Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Thu, 18 Apr 2024 14:03:44 -0400 Subject: [PATCH 11/17] Changed popup info implementation --- src/background/protection/protection.js | 30 +++++---- src/popup/popup.js | 84 +++++++++++++------------ 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index 98a1def..fd8af2f 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -146,19 +146,25 @@ async function updateDomainlist(details) { //get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable) let currentDomain = await getCurrentParsedDomain(); - //initialize the objects - if (!(activeTabID in domPrev3rdParties)){ - domPrev3rdParties[activeTabID] = {}; - } - if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ - domPrev3rdParties[activeTabID][currentDomain] = {}; - } - //as they come in, add the parsedDomain to the object with null value (just a placeholder) - domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; + // console.log("activeTabID: ",activeTabID); + // console.log("DP3P: ", domPrev3rdParties); + console.log("tabs: ", tabs); + let info = tabs[activeTabID]["REQUEST_DOMAINS"]; + let data = Object.keys(info); - let data = JSON.stringify(domPrev3rdParties[activeTabID]); - console.log("setting to storage: ", data); - await storage.set(stores.thirdParties, data, "parties"); + //initialize the objects + // if (!(activeTabID in domPrev3rdParties)){ + // domPrev3rdParties[activeTabID] = {}; + // } + // if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ + // domPrev3rdParties[activeTabID][currentDomain] = {}; + // } + // //as they come in, add the parsedDomain to the object with null value (just a placeholder) + // domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; + + //let data = JSON.stringify(data); + console.log("setting to storage under ", currentDomain, ": ", data); + await storage.set(stores.thirdParties, data, currentDomain); } diff --git a/src/popup/popup.js b/src/popup/popup.js index 7412b83..e9f947a 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -421,11 +421,11 @@ async function showProtectionInfo() { listenerDropdown2Toggle(); let domain = await getCurrentParsedDomain(); - let parties = await storage.get(stores.thirdParties, "parties"); - parties = JSON.parse(parties); - console.log("parties: ", parties[domain]); + let parties = await storage.get(stores.thirdParties, domain); + //parties = JSON.parse(parties); + console.log("parties under ", domain, ": ", parties); - let requestsData = parties[domain]; + let requestsData = parties; console.log("request data: ", requestsData); buildDomains(requestsData); @@ -505,14 +505,16 @@ function addThirdPartyDomainDNSToggleListener(requestDomain) { * @param {Object} requests - Contains all request domains for the current tab * (requests = tabs[activeTabID].requestDomainS; passed from background page) */ -async function buildDomains(requests) { + async function buildDomains(requests) { let domain = await getCurrentParsedDomain(); let items = ""; const domainlistKeys = await storage.getAllKeys(stores.domainlist); const domainlistValues = await storage.getAll(stores.domainlist); - // Sets the 3rd party domain elements - for (let requestDomain in requests) { + // Iterate through requests array + for (let i = 0; i < requests.length; i++) { + const requestDomain = requests[i]; // Get the domain name from the request array + if (requestDomain != domain) { let checkbox = ""; let text = ""; @@ -527,46 +529,46 @@ async function buildDomains(requests) { } items += ` -
  • -
    - ${requestDomain} -
    -
    -
    - ${text} -
    -
    -
    -
    - +
  • +
    + ${requestDomain}
    - - - - -
    -
    -
  • - `; +
    +
    + ${text} +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + + `; } } document.getElementById("dropdown-1-expandable").innerHTML = items; // Sets the 3rd party domain toggle listeners - for (let requestDomain in requests) { + for (let i = 0; i < requests.length; i++) { + const requestDomain = requests[i]; if (requestDomain != domain) { addThirdPartyDomainDNSToggleListener(requestDomain); } From 0d7e86c4dc1cd719f02e8ba96e7db921e7ed705e Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sat, 4 May 2024 16:27:08 -0400 Subject: [PATCH 12/17] Website response changes --- .../protection/listeners-firefox.js | 4 + src/background/protection/protection.js | 73 ++++++++++++------- src/background/storage.js | 2 + src/popup/popup.js | 7 +- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/background/protection/listeners-firefox.js b/src/background/protection/listeners-firefox.js index 7725883..e4e037b 100644 --- a/src/background/protection/listeners-firefox.js +++ b/src/background/protection/listeners-firefox.js @@ -32,6 +32,7 @@ function enableListeners(callbacks) { onHeadersReceived, onBeforeNavigate, onCommitted, + onCompleted, } = callbacks; // (4) global Firefox listeners @@ -47,6 +48,7 @@ function enableListeners(callbacks) { ); chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate); chrome.webNavigation.onCommitted.addListener(onCommitted); + chrome.webNavigation.onCompleted.addListener(onCompleted); } /** @@ -58,12 +60,14 @@ function disableListeners(callbacks) { onHeadersReceived, onBeforeNavigate, onCommitted, + onCompleted, } = callbacks; chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders); chrome.webRequest.onHeadersReceived.removeListener(onHeadersReceived); chrome.webNavigation.onBeforeNavigate.removeListener(onBeforeNavigate); chrome.webNavigation.onCommitted.removeListener(onCommitted); + chrome.webNavigation.onCompleted.removeListener(onCompleted); } export { enableListeners, disableListeners }; diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index fd8af2f..badecc3 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -70,15 +70,17 @@ const listenerCallbacks = { * @param {object} details - retrieved info passed into callback * @returns {array} */ - onBeforeSendHeaders: (details) => { - updateDomainlist(details); + onBeforeSendHeaders: async (details) => { + await updateDomainlist(details); }, /** * @param {object} details - retrieved info passed into callback */ - onHeadersReceived: (details) => { - logData(details); + onHeadersReceived: async (details) => { + await logData(details); + + }, @@ -94,8 +96,12 @@ const listenerCallbacks = { * @param {object} details - retrieved info passed into callback */ onCommitted: async (details) => { - updateDomainlist(details); + await updateDomainlist(details); }, + onCompleted: async (details) => { + await sendData(); + } + }; // closes listenerCallbacks object /******************************************************************************/ @@ -105,6 +111,35 @@ const listenerCallbacks = { /******************************************************************************/ +async function sendData(){ + let currentDomain = await getCurrentParsedDomain(); + // console.log("activeTabID: ",activeTabID); + // console.log("DP3P: ", domPrev3rdParties); + console.log("tabs: ", tabs); + let info = await tabs[activeTabID]["REQUEST_DOMAINS"]; + let data = Object.keys(info); + console.log("test test1: ", tabs[activeTabID]); + console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); + console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); + + console.log("keys test: ", Object.keys(tabs[activeTabID]["REQUEST_DOMAINS"])); + + //initialize the objects + // if (!(activeTabID in domPrev3rdParties)){ + // domPrev3rdParties[activeTabID] = {}; + // } + // if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ + // domPrev3rdParties[activeTabID][currentDomain] = {}; + // } + // //as they come in, add the parsedDomain to the object with null value (just a placeholder) + // domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; + + //let data = JSON.stringify(data); + console.log("setting to storage under ", currentDomain, ": ", data); + await storage.set(stores.thirdParties, data, currentDomain); +} + + function getCurrentParsedDomain() { return new Promise((resolve, reject) => { try { @@ -144,27 +179,6 @@ async function updateDomainlist(details) { } //get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable) - - let currentDomain = await getCurrentParsedDomain(); - // console.log("activeTabID: ",activeTabID); - // console.log("DP3P: ", domPrev3rdParties); - console.log("tabs: ", tabs); - let info = tabs[activeTabID]["REQUEST_DOMAINS"]; - let data = Object.keys(info); - - //initialize the objects - // if (!(activeTabID in domPrev3rdParties)){ - // domPrev3rdParties[activeTabID] = {}; - // } - // if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ - // domPrev3rdParties[activeTabID][currentDomain] = {}; - // } - // //as they come in, add the parsedDomain to the object with null value (just a placeholder) - // domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; - - //let data = JSON.stringify(data); - console.log("setting to storage under ", currentDomain, ": ", data); - await storage.set(stores.thirdParties, data, currentDomain); } @@ -175,7 +189,7 @@ function updatePopupIcon(tabId) { }); } -function logData(details) { +async function logData(details) { let url = new URL(details.url); let parsed = psl.parse(url.hostname); @@ -425,6 +439,11 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { wellknown[tabID] = message.data; let wellknownData = message.data; + console.log("setting WKD at ", domain, ": ", wellknownData); + await storage.set(stores.wellknownInformation, wellknownData, domain); + + //await sendData(); + initIAB(!sendSignal); if (wellknown[tabID] === null && sendSignal == null) { diff --git a/src/background/storage.js b/src/background/storage.js index 4a8afcf..823881a 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -27,6 +27,7 @@ const stores = Object.freeze({ settings: "SETTINGS", domainlist: "DOMAINLIST", thirdParties: "THIRDPARTIES", + wellknownInformation: "WELLKNOWNDATA", }); /******************************************************************************/ @@ -38,6 +39,7 @@ const dbPromise = openDB("extensionDB", 1, { db.createObjectStore(stores.domainlist); db.createObjectStore(stores.settings); db.createObjectStore(stores.thirdParties); + db.createObjectStore(stores.wellknownInformation); }, }); diff --git a/src/popup/popup.js b/src/popup/popup.js index e9f947a..b709a27 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -422,12 +422,15 @@ async function showProtectionInfo() { let domain = await getCurrentParsedDomain(); let parties = await storage.get(stores.thirdParties, domain); + let wellknown = await storage.get(stores.wellknownInformation, domain); //parties = JSON.parse(parties); console.log("parties under ", domain, ": ", parties); let requestsData = parties; console.log("request data: ", requestsData); buildDomains(requestsData); + buildWellKnown(wellknown); + // chrome.runtime.sendMessage({ @@ -667,8 +670,8 @@ chrome.runtime.onMessage.addListener(function (message, _, __) { console.log("info received PPD"); domainsInfo = requests; wellknownInfo = wellknown; - buildDomains(requests); - buildWellKnown(wellknown); + //buildDomains(requests); + //buildWellKnown(wellknown); } if (message.msg === "POPUP_PROTECTION_DATA_REQUESTS") { console.log("info received PPDR"); From 7ce7c5f44366fff5c3380e18097e92bbe8d012b8 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sat, 4 May 2024 18:18:44 -0400 Subject: [PATCH 13/17] 3rd party network changes --- src/background/protection/protection.js | 32 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index badecc3..dc0891d 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -39,6 +39,7 @@ var activeTabID = 0; // Caches current active tab id var sendSignal = true; // Caches if the signal can be sent to the curr domain var domPrev3rdParties = {}; //stores all the 3rd parties by domain (resets when you quit chrome) var globalParsedDomain; +var setup = false; async function reloadVars() { let storedDomainlisted = await storage.get( @@ -71,6 +72,9 @@ const listenerCallbacks = { * @returns {array} */ onBeforeSendHeaders: async (details) => { + // if (!setup){ + // initSetup(); + // } await updateDomainlist(details); }, @@ -79,6 +83,7 @@ const listenerCallbacks = { */ onHeadersReceived: async (details) => { await logData(details); + await sendData(); @@ -98,6 +103,7 @@ const listenerCallbacks = { onCommitted: async (details) => { await updateDomainlist(details); }, + onCompleted: async (details) => { await sendData(); } @@ -112,17 +118,25 @@ const listenerCallbacks = { async function sendData(){ + // chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + // if (tabs.id) { + // activeTabID = tabs.id; + // } + // }); let currentDomain = await getCurrentParsedDomain(); // console.log("activeTabID: ",activeTabID); // console.log("DP3P: ", domPrev3rdParties); - console.log("tabs: ", tabs); - let info = await tabs[activeTabID]["REQUEST_DOMAINS"]; - let data = Object.keys(info); - console.log("test test1: ", tabs[activeTabID]); - console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); - console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); - - console.log("keys test: ", Object.keys(tabs[activeTabID]["REQUEST_DOMAINS"])); + console.log("tabs: ", tabs); + console.log("activeTabID: ", activeTabID); + // console.log("test test1: ", tabs[activeTabID]); + // console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); + // console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); + let data = ["Please reload the site"]; + + if (tabs[activeTabID] !== undefined) { + let info = await tabs[activeTabID]["REQUEST_DOMAINS"]; + data = Object.keys(info); + } //initialize the objects // if (!(activeTabID in domPrev3rdParties)){ @@ -523,6 +537,7 @@ function closeMessagePassing() { */ function onActivatedProtectionMode(info) { activeTabID = info.tabId; + console.log("onActivatedProtectionMode called"); } // Handles misc. setup & setup listeners @@ -537,6 +552,7 @@ function initSetup() { }); chrome.tabs.onActivated.addListener(onActivatedProtectionMode); + setup = true; } function closeSetup() { From 015d9054364e91d1c5724345601b581787b65082 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sun, 5 May 2024 13:26:56 -0400 Subject: [PATCH 14/17] changed active tab handler --- src/background/protection/protection.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index dc0891d..38b249b 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -72,9 +72,6 @@ const listenerCallbacks = { * @returns {array} */ onBeforeSendHeaders: async (details) => { - // if (!setup){ - // initSetup(); - // } await updateDomainlist(details); }, @@ -82,6 +79,9 @@ const listenerCallbacks = { * @param {object} details - retrieved info passed into callback */ onHeadersReceived: async (details) => { + //if (!setup){ + //initSetup(); + //} await logData(details); await sendData(); @@ -123,6 +123,10 @@ async function sendData(){ // activeTabID = tabs.id; // } // }); + + let activeTab = await chrome.tabs.query({ active: true, currentWindow: true }); + let activeTabID = activeTab.length > 0 ? activeTab[0].id : null; + let currentDomain = await getCurrentParsedDomain(); // console.log("activeTabID: ",activeTabID); // console.log("DP3P: ", domPrev3rdParties); @@ -133,6 +137,16 @@ async function sendData(){ // console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); let data = ["Please reload the site"]; + // if (activeTabID == 0){ + // console.log("activeTabID is zero!!!"); + // await chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + // console.log("tabs.id: ",tabs.id); + // if (tabs.id) { + // activeTabID = tabs.id; + // } + // }); + // } + if (tabs[activeTabID] !== undefined) { let info = await tabs[activeTabID]["REQUEST_DOMAINS"]; data = Object.keys(info); From c5ae9818efb2d40edd8c0dfb65cd5d86c3005838 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sat, 11 May 2024 11:03:35 -0400 Subject: [PATCH 15/17] Fixed bleedover bug (issue #350) --- src/background/protection/protection.js | 60 +++++++++++++------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index 38b249b..6e77867 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -130,41 +130,25 @@ async function sendData(){ let currentDomain = await getCurrentParsedDomain(); // console.log("activeTabID: ",activeTabID); // console.log("DP3P: ", domPrev3rdParties); - console.log("tabs: ", tabs); - console.log("activeTabID: ", activeTabID); + // console.log("tabs: ", tabs); + // console.log("activeTabID: ", activeTabID); // console.log("test test1: ", tabs[activeTabID]); // console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); // console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); let data = ["Please reload the site"]; - // if (activeTabID == 0){ - // console.log("activeTabID is zero!!!"); - // await chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - // console.log("tabs.id: ",tabs.id); - // if (tabs.id) { - // activeTabID = tabs.id; - // } - // }); - // } - - if (tabs[activeTabID] !== undefined) { - let info = await tabs[activeTabID]["REQUEST_DOMAINS"]; + + //if (tabs[activeTabID] !== undefined) { + let info = await domPrev3rdParties[activeTabID][currentDomain]; data = Object.keys(info); - } - //initialize the objects - // if (!(activeTabID in domPrev3rdParties)){ - // domPrev3rdParties[activeTabID] = {}; - // } - // if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ - // domPrev3rdParties[activeTabID][currentDomain] = {}; - // } - // //as they come in, add the parsedDomain to the object with null value (just a placeholder) - // domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null; - - //let data = JSON.stringify(data); - console.log("setting to storage under ", currentDomain, ": ", data); - await storage.set(stores.thirdParties, data, currentDomain); + console.log("setting to storage under ", currentDomain, ": ", data); + await storage.set(stores.thirdParties, data, currentDomain); + //} + + //console.log("DP3P: ", domPrev3rdParties[activeTabID][currentDomain]); + + } @@ -202,12 +186,30 @@ async function updateDomainlist(details) { let parsedDomain = parsedUrl.domain; let currDomainValue = await storage.get(stores.domainlist, parsedDomain); + console.log("origin url: ", details.documentUrl); + + let origin_url = new URL(details.documentUrl); + let parsed_origin = psl.parse(origin_url.hostname); + let parsedOrigin = parsed_origin.domain; + if (currDomainValue === undefined) { await storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async } + //let currentDomain = await getCurrentParsedDomain(); + + //get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable) - + if (!(activeTabID in domPrev3rdParties)){ + domPrev3rdParties[activeTabID] = {}; + } + if (!(parsedOrigin in domPrev3rdParties[activeTabID]) ){ + domPrev3rdParties[activeTabID][parsedOrigin] = {}; + } + //as they come in, add the parsedDomain to the object with null value (just a placeholder) + domPrev3rdParties[activeTabID][parsedOrigin][parsedDomain] = null; + + } function updatePopupIcon(tabId) { From 2611993c2d1ff2611da1d1b325af6543a8de13e7 Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Sat, 11 May 2024 11:31:34 -0400 Subject: [PATCH 16/17] Fixed bleedover bug for chrome (Issue #350) --- src/background/protection/protection.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index 6e77867..f95615b 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -130,7 +130,7 @@ async function sendData(){ let currentDomain = await getCurrentParsedDomain(); // console.log("activeTabID: ",activeTabID); // console.log("DP3P: ", domPrev3rdParties); - // console.log("tabs: ", tabs); + console.log("tabs: ", tabs); // console.log("activeTabID: ", activeTabID); // console.log("test test1: ", tabs[activeTabID]); // console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); @@ -186,28 +186,30 @@ async function updateDomainlist(details) { let parsedDomain = parsedUrl.domain; let currDomainValue = await storage.get(stores.domainlist, parsedDomain); - console.log("origin url: ", details.documentUrl); + console.log("origin url: ", details.tabId); - let origin_url = new URL(details.documentUrl); - let parsed_origin = psl.parse(origin_url.hostname); - let parsedOrigin = parsed_origin.domain; + // let origin_url = new URL(details.originUrl); + // let parsed_origin = psl.parse(origin_url.hostname); + // let parsedOrigin = parsed_origin.domain; + + let id = details.tabId; if (currDomainValue === undefined) { await storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async } - //let currentDomain = await getCurrentParsedDomain(); + let currentDomain = await getCurrentParsedDomain(); //get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable) - if (!(activeTabID in domPrev3rdParties)){ - domPrev3rdParties[activeTabID] = {}; + if (!(id in domPrev3rdParties)){ + domPrev3rdParties[id] = {}; } - if (!(parsedOrigin in domPrev3rdParties[activeTabID]) ){ - domPrev3rdParties[activeTabID][parsedOrigin] = {}; + if (!(currentDomain in domPrev3rdParties[activeTabID]) ){ + domPrev3rdParties[id][currentDomain] = {}; } //as they come in, add the parsedDomain to the object with null value (just a placeholder) - domPrev3rdParties[activeTabID][parsedOrigin][parsedDomain] = null; + domPrev3rdParties[id][currentDomain][parsedDomain] = null; } From e0794109377d0d549290a3b3dfdb96dbcd33ec37 Mon Sep 17 00:00:00 2001 From: Mattm27 Date: Fri, 17 May 2024 23:04:18 -0400 Subject: [PATCH 17/17] Refactoring complete (Issue #350) --- src/background/protection/protection.js | 29 ------------------------- src/popup/popup.js | 6 ----- 2 files changed, 35 deletions(-) diff --git a/src/background/protection/protection.js b/src/background/protection/protection.js index f95615b..6279534 100644 --- a/src/background/protection/protection.js +++ b/src/background/protection/protection.js @@ -128,25 +128,13 @@ async function sendData(){ let activeTabID = activeTab.length > 0 ? activeTab[0].id : null; let currentDomain = await getCurrentParsedDomain(); - // console.log("activeTabID: ",activeTabID); - // console.log("DP3P: ", domPrev3rdParties); - console.log("tabs: ", tabs); - // console.log("activeTabID: ", activeTabID); - // console.log("test test1: ", tabs[activeTabID]); - // console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]); - // console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]); let data = ["Please reload the site"]; - //if (tabs[activeTabID] !== undefined) { let info = await domPrev3rdParties[activeTabID][currentDomain]; data = Object.keys(info); - console.log("setting to storage under ", currentDomain, ": ", data); await storage.set(stores.thirdParties, data, currentDomain); - //} - - //console.log("DP3P: ", domPrev3rdParties[activeTabID][currentDomain]); } @@ -185,13 +173,6 @@ async function updateDomainlist(details) { let parsedUrl = psl.parse(url.hostname); let parsedDomain = parsedUrl.domain; let currDomainValue = await storage.get(stores.domainlist, parsedDomain); - - console.log("origin url: ", details.tabId); - - // let origin_url = new URL(details.originUrl); - // let parsed_origin = psl.parse(origin_url.hostname); - // let parsedOrigin = parsed_origin.domain; - let id = details.tabId; if (currDomainValue === undefined) { @@ -342,24 +323,16 @@ function handleSendMessageError() { async function dataToPopupHelper(){ //data gets sent back every time the popup is clicked let requestsData = {}; - - console.log("data to popup helper called"); - - //if (tabs[activeTabID] !== undefined) { let domain = await getCurrentParsedDomain(); let parties = await storage.get(stores.thirdParties, "parties"); parties = JSON.parse(parties); - console.log("parties: ", parties[domain]); requestsData = parties[domain]; - console.log("request data: ", requestsData); - //} return requestsData } // Info back to popup async function dataToPopup(wellknownData) { - console.log("datatopopup called"); let requestsData = await dataToPopupHelper(); //get requests from the helper chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ let popupData = { @@ -378,7 +351,6 @@ async function dataToPopup(wellknownData) { } async function dataToPopupRequests() { - console.log("datatopopuprequests called"); let requestsData = await dataToPopupHelper(); //get requests from the helper console.log("requests data in DTPR: ", requestsData) @@ -471,7 +443,6 @@ async function onMessageHandlerAsync(message, sender, sendResponse) { wellknown[tabID] = message.data; let wellknownData = message.data; - console.log("setting WKD at ", domain, ": ", wellknownData); await storage.set(stores.wellknownInformation, wellknownData, domain); //await sendData(); diff --git a/src/popup/popup.js b/src/popup/popup.js index b709a27..c381274 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -423,11 +423,8 @@ async function showProtectionInfo() { let domain = await getCurrentParsedDomain(); let parties = await storage.get(stores.thirdParties, domain); let wellknown = await storage.get(stores.wellknownInformation, domain); - //parties = JSON.parse(parties); - console.log("parties under ", domain, ": ", parties); let requestsData = parties; - console.log("request data: ", requestsData); buildDomains(requestsData); buildWellKnown(wellknown); @@ -667,16 +664,13 @@ async function buildWellKnown(requests) { chrome.runtime.onMessage.addListener(function (message, _, __) { if (message.msg === "POPUP_PROTECTION_DATA") { let { requests, wellknown } = message.data; - console.log("info received PPD"); domainsInfo = requests; wellknownInfo = wellknown; //buildDomains(requests); //buildWellKnown(wellknown); } if (message.msg === "POPUP_PROTECTION_DATA_REQUESTS") { - console.log("info received PPDR"); let requests = message.data; - console.log("requests: ", requests); buildDomains(requests); } });