Reputation: 11
I am kinda struggling with porting a private chrome extension to firefox. My goal is the following: After a page is loaded, I want to delete all cookies from certain domains (which are stored in a list). I try to retrieve all cookies in my code, but I always get an array of length 0 as a return.. My manifest:
{
"manifest_version": 3,
"name": "My Addon",
"version": "1.0",
"description": "Description of my addon",
"permissions": ["tabs", "cookies", "activeTab", "webNavigation",
"webRequest"
],
"host_permissions": ["<all_urls>"],
"background": {
"scripts": ["background.js"]
},
"icons": {
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"action": {
"default_icon": {
"48": "icons/icon48.png",
"128": "icons/icon96.png"
}
}
}
and my background.js:
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === "complete" && tab.url) {
const domains = ["nzz.ch", "faz.net"]; // Hier kannst du weitere Domänen hinzufügen
const cookies = await browser.cookies.getAll({});
console.log("Alle Cookies:", cookies);
for (const domain of domains) {
if (tab.url.includes(domain)) {
console.log(`${domain} loaded`);
cookies.forEach(cookie => {
if (cookie.domain.includes(domain)) {
console.log("Deleting cookie:", cookie.name);
browser.cookies.remove({
url: `http${cookie.secure ? 's' : ''}://${cookie.domain}${cookie.path}`,
name: cookie.name
});
}
});
}
}
}
});
As I am new to developing webextension, I would like to also understand what I am doing wrong, such that I can improve.
I expected an non-empty array of cookies.
Upvotes: 1
Views: 35