Estoy desarrollando un complemento y al presionar los botones en mi complemento se abren nuevas pestañas. Pero no quiero volver a abrir una pestaña ya abierta. Así que creé una función llamada openTab() . Pero esta función no funciona exactamente como quiero porque hago las comprobaciones con includes() . Por ejemplo, https://www.youtube.com está abierto en el navegador y cuando presiono el botón, https://www.youtube.com/watch?v=9I16FhnSa-c debería abrirse en una nueva pestaña. Pero la función openTab() dice que esta pestaña ya está abierta y actualiza la pestaña existente. ¿Cómo puedo resolver el problema?
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) {} }