change that tab open change url inplace and get active tab from window id
Testing / test (push) Successful in 29s
Package Extension / package-extension (push) Successful in 11s
Build & Publish Package / publish (push) Successful in 43s

This commit is contained in:
2026-04-13 19:50:46 +02:00
parent 9dbe57c66c
commit 5150933319
8 changed files with 90 additions and 10 deletions
+20 -2
View File
@@ -121,6 +121,7 @@ async function dispatch(command, args) {
switch (command) {
// ── Navigation ────────────────────────────────────────────────────────
case "navigate.open": return navOpen(args);
case "navigate.to": return navTo(args);
case "navigate.reload": return navReload(args, false);
case "navigate.hard_reload": return navReload(args, true);
case "navigate.back": return navBack(args);
@@ -132,6 +133,7 @@ async function dispatch(command, args) {
case "tabs.close": return tabsClose(args);
case "tabs.move": return tabsMove(args);
case "tabs.active": return tabsActive(args);
case "tabs.active_in_window": return tabsActiveInWindow(args);
case "tabs.filter": return tabsFilter(args);
case "tabs.count": return tabsCount(args);
case "tabs.query": return tabsQuery(args);
@@ -191,9 +193,11 @@ async function dispatch(command, args) {
// ── Navigation ────────────────────────────────────────────────────────────────
async function navOpen({ url, background, window: windowName, group: groupNameOrId }) {
async function navOpen({ url, background, window: windowName, windowId: explicitWindowId, group: groupNameOrId }) {
let windowId;
if (windowName) {
if (explicitWindowId != null) {
windowId = explicitWindowId;
} else if (windowName) {
const aliases = await getAliases();
const entry = Object.entries(aliases).find(([, v]) => v === windowName);
if (entry) windowId = parseInt(entry[0]);
@@ -221,6 +225,11 @@ async function navOpen({ url, background, window: windowName, group: groupNameOr
return { id: tab.id, url: tab.url };
}
async function navTo({ tabId, url }) {
const tab = await chrome.tabs.update(tabId, { url });
return { id: tab.id, url: tab.url || url };
}
async function navReload({ tabId }, bypassCache) {
const tab = tabId ? { id: tabId } : await getActiveTab();
await chrome.tabs.reload(tab.id, { bypassCache });
@@ -326,6 +335,15 @@ async function tabsActive({ tabId }) {
return { tabId };
}
async function tabsActiveInWindow({ windowId }) {
const activeTabs = await chrome.tabs.query({ windowId, active: true });
const tab = activeTabs[0];
if (!tab) {
throw new Error(`No active tab found for window ${windowId}`);
}
return tabInfo(tab);
}
async function tabsFilter({ pattern }) {
const all = await chrome.tabs.query({});
return all.filter(t => t.url && t.url.includes(pattern)).map(tabInfo);