So I have two questions here. The first is:
I am trying to write a code for an extension that closes idle open tabs in Google Chrome after a set amount of time. For testing, I have made this set time to be 10 seconds. This is my manifest.json
{
"manifest_version": 3,
"name": "Idle Tab Closer",
"version": "1.0",
"permissions": ["tabs", "idle"],
"background": {
"service_worker": "background.js"
}
}
And this is my background.js
chrome.idle.onStateChanged.addListener((state) => {
if (state === "idle") {
chrome.tabs.query({}, (tabs) => {
const currentTime = Date.now();
const tenSeconds = 10 * 1000; // 10 seconds in milliseconds
tabs.forEach((tab) => {
chrome.tabs.get(tab.id, (currentTab) => {
if (currentTab.lastFocusedWindow && currentTab.lastFocusedWindow.focused) {
const tabLastActive = currentTab.lastFocusedWindow.focusedTime || currentTab.lastFocusedWindow.timestamp;
if (currentTime - tabLastActive > tenSeconds) {
chrome.tabs.remove(tab.id);
}
}
});
});
});
}
});
But this code does not work. It does not result in errors, but the tabs still do not close after this set amount of time. What I do is I switch to a tab and then wait for the other tabs to close but they never do.
The second question is simple: Is there a place to keep asking questions safely and get help with my project without spamming stackoverflow or get into risk of having my account closed?
Thank you!