From 3debe8a36fb5aa898d39c4448bea587192248343 Mon Sep 17 00:00:00 2001 From: Rafee Date: Tue, 20 Aug 2024 13:56:55 -0400 Subject: [PATCH] feat #303: change individual cookie removal to browsingData api --- src/_locales | 2 +- src/js/background/assignManager.js | 18 +++++++----------- src/js/popup.js | 20 +++++++++++--------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/_locales b/src/_locales index c640d40..f4676d6 160000 --- a/src/_locales +++ b/src/_locales @@ -1 +1 @@ -Subproject commit c640d4062a5f3da3608d28d9928be614d6bc4fb9 +Subproject commit f4676d69b485a41e3221468b2d4826cae240b1d7 diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index bdbd367..864181c 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -571,18 +571,14 @@ window.assignManager = { return true; }, - async _resetCookiesForSite(pageUrl, cookieStoreId) { - const url = new URL(pageUrl); - // Remove 'www.' from the domain value - const domain = url.hostname.replace(/^www\./, ""); - const cookies = await browser.cookies.getAll({domain: domain, storeId: cookieStoreId}); - for (const cookie of cookies) { - const domain = cookie.domain.startsWith(".") ? cookie.domain.slice(1) : cookie.domain; - const cookieUrl = `${cookie.secure ? "https" : "http"}://${domain}${cookie.path}`; - await browser.cookies.remove({ url: cookieUrl, name: cookie.name, storeId: cookie.storeId }); - } + async _resetCookiesForSite(hostname, cookieStoreId) { + const hostNameTruncated = hostname.replace(/^www\./, ''); // Remove "www." from the hostname + await browser.browsingData.removeCookies({ + cookieStoreId: cookieStoreId, + hostnames: [hostname, hostNameTruncated] // This does not remove cookies from associated domains. To remove all cookies, we have a container storage removal option. + }); - return true; // Success + return true; }, async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) { diff --git a/src/js/popup.js b/src/js/popup.js index 99bcdcf..84be34c 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -131,7 +131,7 @@ const Logic = { setTimeout(() => { notificationCard.classList.remove("is-shown"); - }, 1000); + }, 2000); }); }, @@ -984,12 +984,15 @@ Logic.registerPanel(P_CONTAINER_INFO, { Utils.addEnterHandler(deleteData, async () => { const userContextId = Utils.userContextId(identity.cookieStoreId) - await browser.runtime.sendMessage({ + const result = await browser.runtime.sendMessage({ method: "deleteContainerDataOnly", message: { userContextId } }); - - Logic.notify({messageId: "storageWasClearedConfirmation", placeholders: [identity.name]}); + + if (result.done === true) { + Logic.notify({messageId: "storageWasClearedConfirmation", placeholders: [identity.name]}); + } + this.prepare(); }); @@ -1477,7 +1480,7 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, { /* As we don't have the full or correct path the best we can assume is the path is HTTPS and then replace with a broken icon later if it doesn't load. This is pending a better solution for favicons from web extensions */ const assumedUrl = `https://${site.hostname}/favicon.ico`; - const resetSiteCookiesInfo = browser.i18n.getMessage("resetSiteCookiesTooltipInfo"); + const resetSiteCookiesInfo = browser.i18n.getMessage("clearSiteCookiesTooltipInfo"); const deleteSiteInfo = browser.i18n.getMessage("deleteSiteTooltipInfo"); trElement.innerHTML = Utils.escaped` @@ -1498,13 +1501,12 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, { }); const resetButton = trElement.querySelector(".reset-button"); Utils.addEnterHandler(resetButton, async () => { - const pageUrl = `https://${site.hostname}`; const cookieStoreId = Logic.currentCookieStoreId(); - const result = await Utils.resetCookiesForSite(pageUrl, cookieStoreId); + const result = await Utils.resetCookiesForSite(site.hostname, cookieStoreId); if (result === true) { - Logic.notify({messageId: "cookieResetSuccess", placeholders: []}); + Logic.notify({messageId: "cookiesClearedSuccess", placeholders: [site.hostname]}); } else { - Logic.notify({messageId: "cookiesCouldNotBeReset", placeholders: []}); + Logic.notify({messageId: "cookiesCouldNotBeCleared", placeholders: [site.hostname]}); } }); trElement.classList.add("menu-item", "hover-highlight", "keyboard-nav");