回答

1

不可以。默认情况下,您无法要求某个标签的列表。

但是,您可以监听onUpdate,onCreated等选项卡事件。使用保持不变的tabId,您可以将URL列表保留在后台脚本(background.js)中,该脚本始终在运行已启用。

你会做这样的:

let arr=[]; // At the top of background.js 
browser.tabs.onCreated.addListener(handleCreated); // Somewhere in background.js 

function handleCreated(tab) { 
    let tabId = tab.id; 
    if(arr[tabId]==null) arr[tabId] = []; 
    arr[tabId].push(url); 
} 

function getHistoryForCurrentTab(){ 
    function currentTabs(tabs) { 
     // browser.tabs.query returns an array, lets assume the first one (it's safe to assume) 
     let tab = tabs[0]; 
     // tab.url requires the `tabs` permission (manifest.json) 
     // We will now log the tab history to the console. 
     for(let url of arr[tab.id]){ 
      console.log(url); 
     } 
    } 

    function onError(error) { 
     console.log(`This should not happen: ${error}`); 
    } 

    browser.tabs.query({currentWindow: true, active: true}).then(currentTabs, onError); 
} 

上面的代码是一个概念证明。您需要考虑的一些改进:实现onClosed,它重置该标签的历史记录(arr [tabId] = null),实现onUpdated(肯定需要,与handleCreated中的逻辑相同)。

链接:

+0

所以因此能够保留历史,对每个* *单独标签?因此,当需要时,还可以在当前选项卡上调用历史记录? – Gary

+0

请参阅我添加到答案的代码。 – Smile4ever

+0

好的,谢谢。在我们之前,'FillHistoryMenu'可用,所以很遗憾他们删除了这个。 – Gary

相关问题