I cannot add multiple tabs inside one group tab with an array because it return this error : Uncaught TypeError
Here's my code :
for (let group in result) {
//creating the group title and displaying it in the popup
let groupTitle = document.createElement("p");
groupTitle.style.setProperty(
"--color",
result[group][result[group].length - 1]
);
groupTitle.classList.add("groupTitle");
let tabsIds = [];
//opening the new tab when the text is click
groupTitle.addEventListener("click", () => {
for (let i = 0; i < result[group].length - 1; i++) {
//creating the new tabs one by one
chrome.tabs.create({ url: result[group][i] }, async function (newTab) {
tabsIds.push(newTab.id);
});
}
//creating a group tab with the tab created
let groupId = chrome.tabs.group({ tabIds: tabsIds });
//modifying the group tab
chrome.tabGroups.update(groupId, {
collapsed: false,
title: group,
color: result[group][result[group].length - 1]
});
});
groupsContainer.appendChild(groupTitle);
groupTitle.append(group);
}
});
I think it could come from the data types inside the array but I have no clue on how to solve it, so please I beg for your help.
chrome
API methods that return a Promise or use a callback are asynchronous, so the result is returned after the current synchronous function completes.You need to declare the function as
async
and useawait
on every call: