vanowm
vanowm

Reputation: 10221

MS Edge vertical tabs: scroll to active tab?

In MS Edge with a lot of vertical tabs when a newly created tab moved to near the top, it scrolls the tabs to the bottom, making active (new) tab out of sight. Is there a way prevent tabs from scrolling or at least scroll to the active tab?

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"
}

Upvotes: 2

Views: 655

Answers (2)

vanowm
vanowm

Reputation: 10221

So far the only solution I could find is track previous active tab and when new tab moved, activate previous tab, wait 200ms and activate new tab (delay less than 200ms seems to be very unreliable). It works, but unfortunately it visibly scrolls the tabs.

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);
});

Upvotes: 3

Robbi
Robbi

Reputation: 1507

With MS Edge vertical tabs layout a possible solution may be to pin the tab in this way.

chrome.tabs.onCreated.addListener( tab => {
    chrome.tabs.move(tab.id, {index: 0}, t => {
        chrome.tabs.update(t.id, {pinned: true})
    })
});

EDIT: Pinning a tab moves it to the top positionS, so chrome.tab.move may not be necessary

Upvotes: 0

Related Questions