Search code examples
google-chrome-extension

Opening Tab Next to Active Tab


For my Chrome extension, I need to open a new tab next to the active/current tab. But tab.create method always append the tab at the end of tab list.

Firefox has relatedToCurrent property to set tab position.

Is there any Chrome equivalent for opening tabs next to active tab?


Solution

  • You can use the "index" property to specify the position at calling chrome.tabs.create() function. If you want to open a new tab next to the current tab:

    chrome.tabs.query({
        active: true, currentWindow: true
      }, tabs => {
        let index = tabs[0].index;
        chrome.tabs.create({
          ...,
          index: index + 1,
          ...
        }, tab => {
          ...
        });
      }
    );