Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
Set an alert to current tab from background script: alert is not defined

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!