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

210
Visualizações
Unable to access chrome.tabs.query in the background.js script

I cannot for the life of me figure this out. I am trying to use chrome.tabs.query on my background page to get the current tab to perform an action on a button click. The tab call produces the following error Error handling response: TypeError: Cannot read properties of undefined (reading 'id') From my understanding the return value is undefined. My question is how do I get the tab value? Can I send the tab value through popup.js message?

popup.js

document.addEventListener("DOMContentLoaded", function() {
    setOptions();

    document.getElementById("buttonScan").addEventListener("click", function() {
        loadOptions();
        chrome.runtime.sendMessage({
            "message": "getWords",
            "remove": true,
        });
    });
});

background.js

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    
    if ("getWords" == request.message) {
            chrome.tabs.query({
                    "active": true,
                    "currentWindow": true
                },
                function(tabs) {

                        chrome.tabs.sendMessage(tabs[0].id, {
                            "message": "returnWords",
                            "remove": request.remove,
                            "keywords": chrome.storage.local.get("keywords"),
                            "foreground": chrome.storage.local.get("foreground") || "red",
                            "background": chrome.storage.local.get("background") || "#lightblue",
                        });
                }
            );
    }
});
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