N
N
Nadim Zakirov2021-03-01 13:31:02
JavaScript
Nadim Zakirov, 2021-03-01 13:31:02

How to delete absolutely all cookies in the browser using the Chrome API?

You do not need to answer the question - this is a reminder for yourself for the future. Well, maybe someone else will come in handy.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2021-03-01
@zkrvndm

Sample code for background.js of your extension:

chrome.cookies.getAll({}, function(cookies) {
  
  var count = cookies.length;
  
  console.log('Найдено Cookie '+count+' шт.');
  console.dir(cookies);

  for (var n = 0; n < cookies.length; n++) {
    
    var details = {
      'name': cookies[n]['name'],
      'storeId': cookies[n]['storeId'],
      'url': 'https://' + cookies[n]['domain'] + cookies[n]['path']
    };
    
    chrome.cookies.remove(details, function(result) {
      count--;
      if (count === 0) {
        console.log('Cookie успешно очищены:');
        chrome.cookies.getAll({}, function(cookies) { console.dir(cookies); });
      }
    });
    
  }

});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question