change that tab open change url inplace and get active tab from window id
This commit is contained in:
+20
-2
@@ -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);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "browser-cli",
|
||||
"version": "0.5.7",
|
||||
"version": "0.5.8",
|
||||
"description": "Control your browser from the terminal via browser-cli",
|
||||
"permissions": [
|
||||
"tabs",
|
||||
|
||||
Reference in New Issue
Block a user