Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete cookies chrome extension

I want to delete all cookie on certain domain automatically so I have crafted an extension.I am able to view the cookies for the domain but I didn't find any method to delete them

Here is my code the function eraseCookie is just called one time

Any suggestions ?

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

$(document).ready(function() {


var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
{
  window.alert(cookies[i]);
  eraseCookie(cookies[i].split("=")[0]);
}

});

I am also using jquery but I don't see a problem in that!

    {
        "name": "Gapa",
        "version": "0.1",
        "description": "",
        "browser_action":   {
            "default_icon": "sigla.png",
            "default_title": "",
            "popup": "hello.html"
        },
        "content_scripts": [
        {
          "matches": ["*://*.google.ro/*"],
          "js": ["jquery-1.8.2.min.js","cookie_handler.js"]
        }
      ],
       "icons": {
          "128":"sigla.png" },
       "permissions": [
        "cookies",
        "tabs",
        "*://*.google.ro/*"
      ],
      "manifest_version": 2


    }

LE : Here is how my script file looks now:

$(document).ready(function() {

var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
{
  chrome.cookies.remove({"url": ".google.ro", "name":cookies[i].split("=")[0]}, function(deleted_cookie) { window.alert('deleted cookie') });
}

});
like image 700
opc0de Avatar asked Oct 23 '12 11:10

opc0de


People also ask

Which cookie is automatically deleted?

Cookie Auto Delete. Automatically delete cookies when a tab or the browser is closed! Cookie Auto Delete is an extension that helps you quickly erase cookies for a tab when it closes (Tab-Only mode). Moreover, you can set the addon to remove cookies for all tabs when the browser is closed (Session-Only mode).

Are cookies worth deleting?

You definitely should not accept cookies – and delete them if you mistakenly do. Outdated cookies. If a website page has been updated, the cached data in cookies might conflict with the new site. This could give you trouble the next time you try to upload that page.

Are cookies deleted permanently?

Session cookiesThe cookie is permanently deleted when you close the web browser. Session cookies don't collect any information from your device, so they don't really cause any harm to your privacy.


2 Answers

First of all you must provide cookies permission in your manifest.

Second of all Chrome provides you with cookies api where remove function is localted:

chrome.cookies.remove(object details, function callback);

You can use it like that:

chrome.cookies.remove({"url": "http://domain.com", "name": "cookieName"}, function(deleted_cookie) { console.log(deleted_cookie); });

Try using this to list all cookies for selected domains (inner delete function removes all cookies from this domain):

chrome.cookies.getAll({domain: "domain.com"}, function(cookies) {
    for(var i=0; i<cookies.length;i++) {
        chrome.cookies.remove({url: "http://domain.com" + cookies[i].path, name: cookies[i].name});
    }
});

In your manifest.json add:

  "background": {
    "scripts": ["background.js"]
  },

and in background.js you include proposed function.

like image 197
Arkadiusz 'flies' Rzadkowolski Avatar answered Oct 19 '22 20:10

Arkadiusz 'flies' Rzadkowolski


I pieced together Arkadiusz's answer and got this working:

In manifest.json:

"background": {
    "scripts": ["background.js"]
  },
"permissions": [
    "cookies",
    "https://*/",
    "http://*/"
  ]

In background.js:

chrome.cookies.getAll({domain: ".mydomain.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});
    }
  });
like image 13
Jon Avatar answered Oct 19 '22 20:10

Jon