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

282
Views
Chrome extension – async onMessage response

I'm having an issue with chrome handling. Here is how I handle communication between my content script, and my background service worker.

Content script

const sendMessage = (msg) => {
  return new Promise((resolve) => {
    console.log('1');
    chrome.runtime.sendMessage(msg, (data) => {
      console.log('4');
      resolve(data);
    });
  });
};


sendMessage.then(...)

Background listener

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
  console.log('2');
  myAsyncHandler().then((data) => {
    console.log('3');
    sendResponse(data);
  });
  return true;
});

I have this whole thing running in a new tab, and now:

  1. When I open my first new tab, everything works as expected – 0 issues – log statements in order: 1, 2, 3, 4
  2. When I open my second tab (2 tabs now running), the issue appears as the sendMessage returns null. Log statements appear in order 1, 2, 4, 3.

I've tried to debug this, but no luck at all. I've even tried to log chrome.runtime.lastError when I received null in the sendMessage callback – but that's undefined.

I'd be grateful for all hints on what might be causing it!

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!