MS Edge 垂直标签:滚动到活动标签?

问题描述

在带有许多垂直标签的 MS Edge 中,当新创建的标签移动到顶部附近时,它会将标签滚动到底部,使活动(新)标签看不见。 有没有办法防止标签滚动或至少滚动到活动标签

background.js

/* listen for new tab event */
chrome.tabs.onCreated.addListener( tab =>
{
  /* move tab to the top */
  chrome.tabs.move(tab.id,{index: 0});
});

manifest.json

{
   "background": {
      "persistent": true,"scripts": [ "background.js" ]
   },"description": "open new tabs as first tab","manifest_version": 2,"name": "test","permissions": [ "tabs" ],"version": "0.0.1"
}

解决方法

到目前为止,我能找到的唯一解决方案是跟踪上一个活动选项卡,当新选项卡移动时,激活上一个选项卡,等待 200 毫秒并激活新选项卡(延迟小于 200 毫秒似乎非常不可靠)。它可以工作,但不幸的是它明显滚动了标签。

var lastActiveTab = {};
/* collect active tab for each window at startup */
chrome.tabs.query({active: true},tabs =>
{
  for(let i = 0; i < tabs.length; i++)
  {
    lastActiveTab[tabs[i].windowId] = tabs[0];
  }
})

/* listen for tab switch */
chrome.tabs.onActivated.addListener( info =>
{
  /* work around for a bug https://bugs.chromium.org/p/chromium/issues/detail?id=1213925 */
  setTimeout(() =>
  {
    /* track active tab */
    chrome.tabs.get(info.tabId,tab => lastActiveTab[tab.windowId] = tab);
  },300);
});

/* listen for new tab event */
chrome.tabs.onCreated.addListener( tab =>
{
  /* move tab to the top */
  chrome.tabs.move(tab.id,{index: 0});
  /* activate previous tab */
  chrome.tabs.update(lastActiveTab[tab.windowId].id,{active: true});
  /* wait 200ms and activate new tab */
  setTimeout(() => chrome.tabs.update(tab.id,{active: true}),200);
});
,

对于 MS Edge 垂直选项卡布局,一个可能的解决方案可能是以这种方式固定选项卡。

console.log(searchQuery)

EDIT:固定标签会将其移动到顶部位置S,因此可能不需要 chrome.tab.move