Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda