fix to open new group when not already exists

This commit is contained in:
2026-04-09 08:48:09 +02:00
parent 7c2fa9a9ac
commit 7d6674e9e5
+9 -1
View File
@@ -153,7 +153,9 @@ async function navOpen({ url, background, window: windowName, group: groupNameOr
}
const tab = await chrome.tabs.create({ url, active: !background, windowId });
if (groupNameOrId != null) {
const groupId = await resolveGroupId(groupNameOrId);
let groupId;
try {
groupId = await resolveGroupId(groupNameOrId);
// Close any blank placeholder tabs that were created when the group was made
const groupTabs = await chrome.tabs.query({ groupId });
const placeholders = groupTabs.filter(t =>
@@ -162,6 +164,12 @@ async function navOpen({ url, background, window: windowName, group: groupNameOr
);
await chrome.tabs.group({ tabIds: [tab.id], groupId });
if (placeholders.length) await chrome.tabs.remove(placeholders.map(t => t.id));
} catch (e) {
if (!e.message.startsWith("No tab group found")) throw e;
// Group doesn't exist — create it with the tab already in it
groupId = await chrome.tabs.group({ tabIds: [tab.id] });
await chrome.tabGroups.update(groupId, { title: String(groupNameOrId) });
}
}
return { id: tab.id, url: tab.url };
}