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

218
Visualizações
Chrome extension message sending from background to content issue

I'm trying to send the current active URL from any updated tab to it's respective content script with the code below. I'm having trouble confirming receipt of any message in the content script/page console. However, the console.log's in background.js are showing up..

I've also noticed that sometimes the changeInfo.url will send as undefined? If I remove the if (changeInfo.url) { conditional from background.js, the background script will log out 2-3 times per page-load, with the latter instances logging changeInfo.url as undefined.

I'm new to Chrome extension development, what am I missing? Thanks!

background.js :

chrome.tabs.onUpdated.addListener( 
    function(tabId, changeInfo, tab) {
    if (changeInfo.url) {
        console.log(tabId, changeInfo.url, tab);
        chrome.tabs.sendMessage( tabId, {
            message: 'hello!',
            url: changeInfo.url
        })
    }
});

content.js :

chrome.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
        console.log("this is the url:" + request.url)
    }
)
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