我想使用 JavaScript 洗掉組選項卡。
我有當前的選項卡 ID,然后我得到當前的組選項卡 ID(如果當前選項卡不在組選項卡中,則回傳 -1)。
現在我想知道是否有這樣的事情:
chrome.tabs.remove(tabId)
但對于組選項卡,更像:
chrome.tabGroups.remove(groupId).
如果有幫助,這是我的代碼:
chrome.tabs.query({ active: true, currentWindow: true }, async function (tabs) {
console.log(tabs[0].id, tabs[0].groupId);
let currentTab = tabs[0].id;
let currentGroupId = tabs[0].groupId;
//get all the infos about the group
let infos = await chrome.tabGroups.get(tabs[0].groupId);
}
);
uj5u.com熱心網友回復:
使用 chrome.tabs.query 查找具有相同 groupId 的選項卡,然后使用這些選項卡的 id 陣列呼叫 chrome.tabs.remove:
async function closeGroup() {
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
const groupTabs = await chrome.tabs.query({groupId: tab.groupId});
await chrome.tabs.remove(groupTabs.map(t => t.id));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/463968.html
標籤:javascript 谷歌浏览器扩展 标签
上一篇:未呈現新的屬性值
