Clear cookies ondisabled event for chrome extension

Viewed 25

I have this code in my chrome extension! but I would like to clear cookies on Disabled event! .Whenever an extension is disabled or uninstalled it will clear all the cookies.

In manifest.json:

    "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});
    }
  });
1 Answers

You don't get any event when your extension is disabled or uninstalled.

You could make cookies relatively short-lived or session cookies - that way they won't persist far beyond your extension's install - but by design you can't react to users disabling your extension.

If you control the domain for which cookies are being set, then you can use chrome.runtime.setUninstallURL to force Chrome to open a page that clears the cookies - this will cover the uninstall part, but not the disable part. There's nothing you can do for disable to clear immediately.

Related