Chrome extension timer - API issue?

Viewed 161

I'm creating a Pomodoro timer program, and I can't figure out how to keep the timer running in the background, after I unfocus the popup.
I've been working on this for a bit, but I currently have all the code for the actual timer in the background script. I was hoping to use the runtime API in popup.js to send a one-time message to start the timer in background.js, and then whenever the user opens the extension, to return what the timer is set to.

I'm also not entirely sure I'm approaching the question correctly.

The code wasn't working, so I simplified it down to just sending the message and trying to get a response, which I found is the problem.

Code:
popup.js:

chrome.runtime.sendMessage({greeting: 'hello'}, function(response) {
    console.log(response.farewell)
});

background.js:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.greeting == 'hello') {
      sendResponse({farewell: 'goodbye'})
      toggleClock();
    }
  });

//working toggleClock() function

manifest.json:


"browser_action": {
        "default_popup":"popup.html",
        "default_title":"Flexidoro",
        "default_icon":"flexidoro.png"
    },

    "background": {
        "scripts": ["background.js"],
        "persistent": false
    },


    "permissions": [ "storage", "alarms" ]

There aren't any errors in the extension error log, and there also isn't anything in the console.
Am I taking the right approach?
Thanks!
0 Answers
Related