I want to make the cookie deletion code work after the same period of time with updating the page, in order to delete the cookies and update the page with it
Auto refresh manifest
{
"manifest_version": 3,
"name": "Auto Page Refresh",
"version": "1.0",
"description": "Automatically refresh a webpage every 5 seconds.",
"permissions": [
"activeTab",
"tabs"
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
}
},
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"commands": {
"toggle": {
"suggested_key": {
"default": "Ctrl+Shift+R",
"mac": "MacCtrl+Shift+R"
},
"description": "Toggle Auto Refresh"
}
},
"background": {
"service_worker": "background.js"
}
}
popup.js
let refreshIntervalId = null;
function toggleAutoRefresh() {
const startStopButton = document.getElementById("startStopButton");
const refreshIntervalInput = document.getElementById("refreshInterval");
if (refreshIntervalId) {
clearInterval(refreshIntervalId);
refreshIntervalId = null;
startStopButton.textContent = "Start";
} else {
const intervalValue = parseInt(refreshIntervalInput.value);
if (intervalValue <= 0 || isNaN(intervalValue)) {
alert("Please enter a valid refresh interval (seconds).");
return;
}
startStopButton.textContent = "Stop";
refreshIntervalId = setInterval(() => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
chrome.tabs.reload(currentTab.id);
});
}, intervalValue * 1000); // Convert to milliseconds
}
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("startStopButton").addEventListener("click", toggleAutoRefresh);
});
popup.html
<html>
<head>
<title>Auto Page Refresh</title>
</head>
<body>
<h2>Auto Page Refresh</h2>
<input type="number" id="refreshInterval" placeholder="Enter refresh interval (seconds)" />
<button id="startStopButton">Start</button>
<script src="popup.js"></script>
</body>
</html>
Cookie Remover manifest
{
"manifest_version": 2,
"name": "CookieRemover",
"version": "0.0.1",
"description": "remove cookies of current page",
"author": "tricora",
"browser_action": {
"default_icon": "images/icon128.png",
"default_title": "Remove Cookies of current page"
},
"permissions": [
"tabs",
"cookies",
"*://*/*"
],
"background": {
"scripts": ["background.js"]
}
}
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.cookies.getAll({
url: tab.url
}, function(cookies) {
var url = new URL(tab.url);
var domain = url.hostname;
cookies.forEach(function(cookie) {
chrome.cookies.remove({
url: url.origin,
name: cookie.name
});
});
});
});
Make the cookie deletion code work after the same period of time while refreshing the page, in order to delete the cookies and update the page with it

