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

170
Views
Passing messages between service worker and popup.js

I'm currently writing a Chrome extension and I'm having trouble passing messages between the service worker and popup scripts. The service worker script is supposed to send a message to the popup script whenever a sign-out event is detected, but i keep getting the following error

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

The service worker invokes this method whenever a sign-out event is detected:

function inputController() {
  var store, remainingSessions, request, port;
  store = getObjectStore("readonly");
  request = store.getAll();
  request.onsuccess = function () {
    remainingSessions = request.result;
    port = chrome.runtime.connect({ name: "RemainingSessions" });
    port.postMessage(remainingSessions);
    console.log("msg sent");
  };
}

This is the code for popup.js

chrome.runtime.onConnect.addListener(function (port) {
  port.onMessage.addListener(function (remainingSessions) {
    console.assert(port.name === "RemainingSessions");
    console.log("Message received " + remainingSessions);
  });
});

I've looked around for the solution, but I haven't found much on this. Any advice or pointers on what I should change?

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!