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

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