Delete all cookies in the browser using js?

40 Views Asked by At

how can I delete all cookies in the browser using js? I found an extension for firefox that uses API cookies, but it does not delete all data:

var count = 0;

browser.cookies.getAll({}, function(cookies) {
  count = cookies.length;
  document.getElementById("cookie-counter").innerHTML = count;
});

function clearAllCookies() {
  console.log("cookies cleared");
  browser.cookies.getAll({}, function(cookies) {
    for (var i in cookies) {
      removeCookie(cookies[i]);
    }
  });
}

function removeCookie(cookie) {
  var url = "http" + (cookie.secure ? "s" : "") + "://" + cookie.domain +
    cookie.path;
  browser.cookies.remove({
    "url": url,
    "name": cookie.name
  });
}

document.addEventListener('DOMContentLoaded', function() {
  var link = document.getElementById('clear-cookies');
  // onClick's logic below:
  link.addEventListener('click', function() {
    clearAllCookies();
  });
});

But the data remains in the cookie storage in the browser settings. Why does this happen and is it possible to completely clean them using js? enter image description here

0

There are 0 best solutions below