background.js 927 B

12345678910111213141516171819202122232425262728293031323334
  1. chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  2. if (request.action === "clearCookies") {
  3. const url = request.url;
  4. chrome.cookies.getAll({ url }, (cookies) => {
  5. if (cookies.length === 0) {
  6. sendResponse({ success: true, message: "No cookies found for this site" });
  7. return;
  8. }
  9. let clearedCount = 0;
  10. cookies.forEach((cookie) => {
  11. chrome.cookies.remove({
  12. url,
  13. name: cookie.name
  14. }, () => {
  15. clearedCount++;
  16. if (clearedCount === cookies.length) {
  17. sendResponse({
  18. success: true,
  19. message: `Cleared ${cookies.length} cookies`
  20. });
  21. }
  22. });
  23. });
  24. // Handle case where we need to wait for async operations
  25. return true;
  26. });
  27. // Indicate we want to send response asynchronously
  28. return true;
  29. }
  30. });