I am new to Chrome extensions, but I have been trying to learn how to create one. Right now, I am working on a very simple extension that times how long you spend on your computer (or more specifically the Chrome web browser).
I managed to get the timer working on the extension's popup, but every time I close the popup and reopen it the timer resets to 0. I have been trying to get the timer to keep running in the background but nothing seems to be working. Below is my background.js file.
var time = 0;
function start() {
increment();
}
function increment() {
setInterval(function() {
time++;
var mins = Math.floor(time/10/60);
var secs = Math.floor(time/10);
if (mins < 10)
mins = "0" + mins;
if (secs < 10)
secs = "0" + secs;
document.getElementById("time").innerHTML = mins + ":" + secs;
}, 100);
}
start();
All I really want is the timer to keep running even when the popup is closed.