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

204
Vistas
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 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