Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!