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) {}
}