fix to open new group when not already exists
This commit is contained in:
+17
-9
@@ -153,15 +153,23 @@ async function navOpen({ url, background, window: windowName, group: groupNameOr
|
|||||||
}
|
}
|
||||||
const tab = await chrome.tabs.create({ url, active: !background, windowId });
|
const tab = await chrome.tabs.create({ url, active: !background, windowId });
|
||||||
if (groupNameOrId != null) {
|
if (groupNameOrId != null) {
|
||||||
const groupId = await resolveGroupId(groupNameOrId);
|
let groupId;
|
||||||
// Close any blank placeholder tabs that were created when the group was made
|
try {
|
||||||
const groupTabs = await chrome.tabs.query({ groupId });
|
groupId = await resolveGroupId(groupNameOrId);
|
||||||
const placeholders = groupTabs.filter(t =>
|
// Close any blank placeholder tabs that were created when the group was made
|
||||||
t.id !== tab.id &&
|
const groupTabs = await chrome.tabs.query({ groupId });
|
||||||
(t.url === "chrome://newtab/" || t.url === "about:blank" || t.pendingUrl === "chrome://newtab/")
|
const placeholders = groupTabs.filter(t =>
|
||||||
);
|
t.id !== tab.id &&
|
||||||
await chrome.tabs.group({ tabIds: [tab.id], groupId });
|
(t.url === "chrome://newtab/" || t.url === "about:blank" || t.pendingUrl === "chrome://newtab/")
|
||||||
if (placeholders.length) await chrome.tabs.remove(placeholders.map(t => t.id));
|
);
|
||||||
|
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 };
|
return { id: tab.id, url: tab.url };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user