From 7d6674e9e5698061e122591e60e47b3509ce551e Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Thu, 9 Apr 2026 08:48:09 +0200 Subject: [PATCH] fix to open new group when not already exists --- extension/background.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/extension/background.js b/extension/background.js index 5345cb5..65fa179 100644 --- a/extension/background.js +++ b/extension/background.js @@ -153,15 +153,23 @@ 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); - // 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 => - t.id !== tab.id && - (t.url === "chrome://newtab/" || t.url === "about:blank" || t.pendingUrl === "chrome://newtab/") - ); - await chrome.tabs.group({ tabIds: [tab.id], groupId }); - if (placeholders.length) await chrome.tabs.remove(placeholders.map(t => t.id)); + 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 => + t.id !== tab.id && + (t.url === "chrome://newtab/" || t.url === "about:blank" || t.pendingUrl === "chrome://newtab/") + ); + 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 }; }