Chrome中Tab.active和Tab.highlighted的区别

在阅读 chrome.tabs 的文档时,highlighted 属性让我感到非常困惑。既然已经有 active 属性用来表示 tab 是否为当前聚焦(focused)的 tab 了,highlighted 属性代表了什么呢?

看了这里的解释之后,我恍然大悟。原来 tab 是可以只“选中”而不“聚焦”的,按住 Ctrl/Command 键后就可以选中多个 tab 进行操作。highlighted 属性表示的就是“被选中”的状态,和 active 属性是相互独立的。这不,甚至还学会了一个浏览器使用小技巧。

chrome.Tab.activechrome.Tab.highlightedchrome.tabs.onActivatedchrome.tabs.onHighlighted,以及 chrome.tabs.updateupdateProperties 参数中的 activehighlighted 都遵循上述区别。

值得注意的是,chrome.tabs.highlight 方法虽然叫 highlight,但是会聚焦传入的第一个 tab。官方文档的描述如下:

Highlights the given tabs and focuses on the first of group. Will appear to do nothing if the specified tab is currently active.