Hi DEV Community,
I’m working on a JavaScript-based browser extension to help developers take short mindfulness breaks during coding sessions to improve focus. I found resources like CalMyTime with quick relaxation exercises, and I want to create a timer that triggers a notification linking to such exercises every hour. I’ve tried using setInterval for the timer in a basic script:
setInterval(() => {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon.png',
title: 'Mindfulness Break',
message: 'Time for a quick relaxation exercise!'
});
}, 3600000); // 1 hour
The issue is the timer resets when the browser restarts, and I’m unsure how to persist it using chrome.storage. I also want to ensure notifications work reliably across Chrome and Firefox. Has anyone built a similar extension or used libraries to handle persistent timers and notifications? I checked MDN’s WebExtensions docs but couldn’t find a clear example for this use case. Any code snippets or tool recommendations (e.g., from npm or GitHub) would be great!
Top comments (0)