
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@vorthain/tab-safe-timers
Advanced tools
Web Worker-powered timer functions that continue running accurately when browser tabs are in the background
Web Worker-powered timer functions that continue running accurately when browser tabs are in the background. Zero configuration required!
Modern browsers throttle JavaScript timers (setTimeout, setInterval) when tabs are in the background to save battery and improve performance. This can break functionality that depends on accurate timing, such as:
This library replaces the native timer functions with Web Worker-based implementations that run in a separate thread, unaffected by background tab throttling.
npm install @vorthain/tab-safe-timers
import { initTabSafeTimers } from '@vorthain/tab-safe-timers';
// Initialize once at app startup
initTabSafeTimers();
// Your existing timer code now works in background tabs!
setInterval(() => {
console.log('This runs every second, even in background tabs!');
}, 1000);
That's it! No configuration files, no worker setup, no build steps required.
// App.js
import { useEffect } from 'react';
import { initTabSafeTimers, destroyTabSafeTimers } from '@vorthain/tab-safe-timers';
function App() {
useEffect(() => {
// Initialize on mount
initTabSafeTimers();
// Cleanup on unmount (optional)
return () => {
destroyTabSafeTimers();
};
}, []);
// Use timers normally anywhere in your app
useEffect(() => {
const interval = setInterval(() => {
console.log('Background-safe timer!');
}, 1000);
return () => clearInterval(interval);
}, []);
return <div>Your app</div>;
}
// main.js
import { createApp } from 'vue';
import { initTabSafeTimers } from '@vorthain/tab-safe-timers';
import App from './App.vue';
// Initialize before creating app
initTabSafeTimers();
createApp(App).mount('#app');
// pages/_app.js or app/layout.js
import { useEffect } from 'react';
import { initTabSafeTimers } from '@vorthain/tab-safe-timers';
export default function App({ Component, pageProps }) {
useEffect(() => {
initTabSafeTimers();
}, []);
return <Component {...pageProps} />;
}
initTabSafeTimers()Initializes the tab-safe timer system. Call this once when your application starts.
Returns: TabSafeTimers instance
Throws: Error if initialization fails (e.g., not in a browser environment or Web Workers not supported)
// Simple usage
initTabSafeTimers();
// With error handling
try {
initTabSafeTimers();
} catch (error) {
console.warn('Tab-safe timers not available:', error);
// Your app still works with regular timers
}
destroyTabSafeTimers()Destroys the timer system and restores native timer functions. This is optional - you only need to call this if you want to clean up resources or disable the tab-safe functionality.
destroyTabSafeTimers();
getTabSafeTimers()Returns the current TabSafeTimers instance or null if not initialized.
const instance = getTabSafeTimers();
if (instance) {
console.log('Tab-safe timers are active');
}
✅ Works perfectly - Web Workers bypass background tab throttling completely on desktop browsers (Chrome, Firefox, Safari, Edge).
⚠️ Works most of the time but with caveats:
Bottom line: This library solves the vast majority of timer-throttling issues, but nothing in JavaScript can guarantee 100% uptime in background mobile tabs due to OS-level restrictions.
initTabSafeTimers();
let secondsElapsed = 0;
setInterval(() => {
secondsElapsed++;
updateUI(secondsElapsed);
}, 1000); // Stays accurate even in background
initTabSafeTimers();
// Check session every 30 seconds, even in background tabs
setInterval(async () => {
const response = await fetch('/api/session/heartbeat');
if (!response.ok) {
handleSessionExpired();
}
}, 30000);
initTabSafeTimers();
// Keep data fresh even when user switches tabs
setInterval(async () => {
const data = await fetchLatestData();
updateStore(data);
}, 5000);
The package includes complete TypeScript definitions:
import { initTabSafeTimers, destroyTabSafeTimers, getTabSafeTimers } from '@vorthain/tab-safe-timers';
// Full type safety
const instance = initTabSafeTimers();
FAQs
Web Worker-powered timer functions that continue running accurately when browser tabs are in the background
The npm package @vorthain/tab-safe-timers receives a total of 2 weekly downloads. As such, @vorthain/tab-safe-timers popularity was classified as not popular.
We found that @vorthain/tab-safe-timers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.