Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
255 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have done this thing in my extension

delete_cookie('cookies_name');

var delete_cookie = function(name) {
    document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
};

that work fine for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...