The Tab Inactivity Timer: How Long Before a Tab Suspends
The inactivity timer is the delay a tab must sit unused before Scalpel suspends it. The clock starts when you last looked at the tab; opening the tab, or loading a new page in it, resets the clock to zero.
Why it matters
You don't want to suspend every tab the moment you open it. But you also don't want to remember which tabs you've looked at recently and which ones you forgot about six hours ago. The inactivity timer automates this: it watches your tabs, and when one sits ignored for long enough, it suspends automatically. You pick how long "long enough" is: shorter timers free memory faster and reload more often; longer timers reload less but hold more RAM. There's no universally right answer, so Scalpel lets you tune it.
How it works
The inactivity timer works through Chrome's chrome.alarms API. When you open Scalpel, it sets up one repeating alarm that fires every minute. On each tick, Scalpel checks every tab and sees whether it's older than your timer setting.
What counts as activity? The clock resets when you:
- Switch to the tab (bring it to focus)
- Load a new page in it (follow a link, type a URL, reload)
- Interact with it (scroll, click, type)
What doesn't count? Network noise, service worker updates, or background API calls don't reset the clock. Only user interaction does.
The tab you're viewing never suspends, whatever the timer says. Scalpel always protects the active tab. If you're looking at a tab, it can't be suspended (because a suspended active tab would reload immediately, which would be jarring).
When the timer expires, Scalpel checks the tab against all exclusions (pinned, audible, unsaved input, never-suspend list). If the tab doesn't match any exclusion, it gets suspended.
What does not matter
There's no "best" timer setting. You'll see people online insist that five minutes is optimal, or that thirty minutes is the only sensible choice. They're wrong. The right number is whatever makes your browsing feel smooth. Some people set it to five minutes and don't mind the reloads. Others set it to two hours because their workflow involves keeping lots of reference tabs open. Both are fine.
The timer doesn't care about background tabs versus foreground tabs. The moment you switch away from a tab, the clock starts ticking. It doesn't matter whether you switched to another tab or another application.
Browser restart doesn't reset the timer for every tab. When you restart Chrome, Scalpel has no way to know how long each tab has been sitting unused. It treats all restored tabs as having zero activity time, which means they'll be suspended immediately on the first sweep (unless they're protected by an exclusion). If you want to preserve your tabs across a restart, turn off the suspension sweep before you close the browser, or use never-suspend list entries for the sites you want to keep awake.
Code example
Here's how the timer logic works under the hood:
// Set up a repeating alarm that fires every minute
chrome.alarms.create("checkInactivity", { periodInMinutes: 1 });
// Listen for the alarm
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === "checkInactivity") {
const timerMinutes = 10; // User's setting
const now = Date.now();
// Get all tabs and check each one
chrome.tabs.query({}, (tabs) => {
tabs.forEach((tab) => {
// Get the last activity time from storage
chrome.storage.session.get(`lastActivity_${tab.id}`, (result) => {
const lastActivity = result[`lastActivity_${tab.id}`] || now;
const inactiveFor = (now - lastActivity) / 1000 / 60; // minutes
// If inactive longer than timer, suspend (unless excluded)
if (inactiveFor > timerMinutes && !isExcluded(tab)) {
chrome.tabs.discard(tab.id);
}
});
});
});
}
});
// Record activity when user interacts with a tab
chrome.tabs.onActivated.addListener((activeInfo) => {
chrome.storage.session.set({
[`lastActivity_${activeInfo.tabId}`]: Date.now()
});
});
When the user changes the timer in settings, Scalpel just updates the stored value. The check still runs every minute against that new number.
How Scalpel shows it
In Scalpel's settings panel, there's a slider for the inactivity timer. It defaults to a sensible middle ground (often around 10–20 minutes, depending on your browser's settings). You can drag the slider left to be more aggressive (suspend faster), or right to be more lenient (hold tabs open longer). The number updates in real-time as you move the slider. Hit Save and Scalpel applies the new setting immediately. No browser restart needed.
You can also pause the automatic sweep entirely (see pause-tab-suspension) if you want to suspend manually for a while, then resume. Pausing disables the timer without changing your timer setting.