I'm trying to create a pomodoro extension. When the timer reaches certain times, it will alert the user. This is the context in my background.js file in which I'm trying to call alert().
chrome.runtime.onConnect.addListener(function(port) {
popupPort = port;
port.onMessage.addListener(function(msg) {
if (msg.cmd == "START_TIMER") {
currentPomodoro = 1500;
totalSessionTime = 0;
buttonMode = "End";
popupPort.postMessage({countdown: "00:25:00", totalTime: "00:00:00", mode: buttonMode})
pomodoroInterval = setInterval(incrementTimer, 1000);
}
})
})
const incrementTimer = () => {
currentPomodoro = currentPomodoro - 1;
totalSessionTime = totalSessionTime + 1;
var pts = 0;
if (currentPomodoro % 5 == 0) pts = 10;
chrome.storage.sync.get("points", (data) => {
var total = data.points + pts
chrome.storage.sync.set({"points": total});
var countdownTimer = secToTimer(currentPomodoro);
var sessionTimer = secToTimer(totalSessionTime);
popupPort.postMessage({countdown: countdownTimer, totalTime: sessionTimer, points: total})
})
if (currentPomodoro == 1498) {
popupPort.postMessage({alert: "break"})
alert("Break soon");
}
}
This results in Uncaught ReferenceError: alert is not defined. Calling it from my popup.js file also results in the same error. My only workaround is to instead do chrome.windows.create but that's less preferable.