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

145
Views
Checking if the tab is already open for the chrome extension and opening a new tab accordingly

I'm developing a plugin and pressing buttons in my plugin opens new tabs. But I don't want to reopen an already open tab. So I created a function called openTab(). But this function doesn't work exactly the way I want because I do the checks with includes() . For example, https://www.youtube.com is open in the browser and when I press the button, https://www.youtube.com/watch?v=9I16FhnSa-c should open in a new tab. But the openTab() function says this tab is already open and refreshes the existing tab. How can I solve the problem?

JS

function openTab(tabUrl, historyLabel, historyHostName) {
    var isTabActive = false;
    var tabId = 0;
    totalHistoryContent++;
    chrome.tabs.query({}, function(tabs) { 
        for(var i=0;i<tabs.length;i++) {
            if(tabs[i].url.toLowerCase().includes(tabUrl.toLowerCase()) == true || tabUrl.toLowerCase().includes(tabs[i].url.toLowerCase()) == true) {
                isTabActive = true;
                tabId = tabs[i].id;
                break;
            }
        }

        if(isTabActive == false) {
            chrome.tabs.create({ url:tabUrl });
        } else{
            chrome.tabs.update(tabId, {selected: true});
            chrome.tabs.reload(tabId);
        }
    });

    try {
        if(tabUrl.includes("chrome-extension://" + chrome.runtime.id + "/popup.html") == false && tabUrl.includes("chrome://extensions/?id=" + chrome.runtime.id) == false) {
            setHistory(historyLabel, historyHostName);
        }
    } catch (error) {}
}
about 4 years ago · Santiago Gelvez
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!