Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 640
John Sewell Avatar asked Mar 03 '16 18:03

John Sewell


1 Answers

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 => {
      ...
    });
  }
);
like image 88
Yoichiro Tanaka Avatar answered Oct 29 '22 10:10

Yoichiro Tanaka