feat #303: change individual cookie removal to browsingData api

This commit is contained in:
Rafee 2024-08-20 13:56:55 -04:00
parent 606e08d2b7
commit 3debe8a36f
3 changed files with 19 additions and 21 deletions

@ -1 +1 @@
Subproject commit c640d4062a5f3da3608d28d9928be614d6bc4fb9
Subproject commit f4676d69b485a41e3221468b2d4826cae240b1d7

View file

@ -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) {

View file

@ -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`
<td>
@ -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");