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

260
Views
chrome.tabs.sendMessage returns a error about a closed port, despite the return true

I know that this question has already been answered, but none of the previous answers helped me. I am recently in JS and still do not understand the intricacies of all things.

When I try to send a message from the pop-up to the script content tab and get a response to the message, I get an error (below). Without responding to the message, everything works fine.

Spent a lot of time reading the chrome extensions docs and digging through the forums, but everything I don't try returns me to the error:

Unchecked runtime.lastError: The message port closed before a response was received.

I tried to return true and promises, but still marking time. Popup code and content script are below.

// popup side
let params = {
    active: true,
    // lastFocusedWindow: true
};
chrome.tabs.query(params, init);
function init(tabs) {
    htmlStates.url = tabs[0].url;
    chrome.tabs.sendMessage(tabs[0].id, htmlStates, (response) => {
        console.log(response);
    })
}
// content script side
function messageCheck(message, sender, sendResponse) {
    // return true;
    // return Promise.resolve({response: 'received'});
    sendResponse({response: 'some response'})
}
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!