this is my first program and i'm getting lost..
I try to do an extension that delete one cookie from specific web when I click on the icon of this extension.
What's wrong with my code?
Thank you all!
manifest.json:
{
"name" : "Delete Cookie",
"version" : "0.8",
"manifest_version": 2
"description" : "Delete Cookie by icon clicked",
"permissions": [ "cookies", "http://www.example.com" ],
"icons": { "16": "cookie.png", "48": "cookie.png", "128": "cookie.png" },
"browser_action": {
"default_icon": "cookie.png"
},
"background": {
"scripts": ["background.js"]
},
}
backgroung.js:
chrome.browserAction.onClicked.addListener(DeletCookie)
function DeletCookie()
{
chrome.cookies.remove({url:"http://www.example.com", name: "CookieName"})
}
EDIT
I tried this:
chrome.cookies.getAll({domain: "www.example.com"}, function(cookies) {
for(var i=0; i<cookies.length;i++) {
console.log(cookies[i]);
chrome.cookies.remove({url: "https://" + cookies[i].domain + cookies[i].path, name: cookies[i].name});
}
});
and it worked,but this way it delete the cookie every time it shwoes up.
So I try:
function DeleteCookie (){
chrome.cookies.getAll({domain: "www.example.com"}, function(cookies) {
for(var i=0; i<cookies.length;i++) {
console.log(cookies[i]);
chrome.cookies.remove({url: "https://" + cookies[i].domain + cookies[i].path, name: cookies[i].name});
}
});
};
chrome.browserAction.onClicked.addListener(DeletCookie) ;
and this way it doesn't work again
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…