1
我首次使用Firefox Web擴展API。我想通過點擊一個按鈕來刪除example.com的所有cookies。我有以下代碼,但沒有得到任何結果。通過點擊按鈕刪除Cookie - 網絡擴展程序API
background.js
function onRemoved(cookie) {
console.log(`Removed: ${cookie}`);
}
function onError(error) {
console.log(`Error removing cookie: ${error}`);
}
function removeCookie() {
var removing = browser.cookies.remove({
url: "example.com"
});
removing.then(onRemoved, onError);
}
browser.browserAction.onClicked.addListener(removeCookie);
的manifest.json
{
"description": "RemoveCookie",
"manifest_version": 2,
"name": "remove-cookies",
"version": "1.0",
"icons": {
"48": "icons/icon.png"
},
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icons/icon.png",
"default_title": "Remove Cookie!"
},
"permissions": [
"*://*.example.com/*",
"cookies"
]
}
THX該解決方案! – HeScm
@HeScm太棒了!考慮接受答案,如果它適合你 – Maluen