Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda