Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/tabs/move/index.md
6557 views
------{{AddonSidebar()}}
Moves one or more tabs to a new position in the same window or to a different window.
You can only move tabs to and from windows whose {{WebExtAPIRef('windows.WindowType', 'WindowType')}} is "normal".
This is an asynchronous function that returns a Promise.
Syntax
Parameters
tabIds:
integerorarrayofinteger. ID of the {{WebExtAPIRef('tabs.Tab', 'tab')}} to move, or an array of tab IDs.
moveProperties:
object. An object that specifies where to move the tab(s).windowId{{optional_inline}}:
integer. The ID of the window to which you want to move the tab(s). If you omit this, then each tab intabIdswill be moved toindexin its current window. If you include this, andtabIdscontains more than one tab, then the first tab intabIdswill be moved toindex, and the other tabs will follow it in the order given intabIds.
index:
integer. The index position to move the tab to, starting at 0. A value of -1 will place the tab at the end of the window.If you pass a value less than -1, the function will throw an error.
Note that you can't move pinned tabs to a position after any unpinned tabs in a window, or move any unpinned tabs to a position before any pinned tabs. For example, if you have one or more pinned tabs in the target window and
tabIdsrefers to an unpinned tab, then you can't pass 0 here. If you try to do this, the function will silently fail (it will not throw an error).
Return value
A Promise that will be fulfilled with a {{WebExtAPIRef('tabs.Tab')}} object or an array of {{WebExtAPIRef('tabs.Tab')}} objects, containing details about the moved tabs. If no tabs were moved (for example, because you tried to move an unpinned tab before a pinned tab) this will be an empty array. If any error occurs, the promise will be rejected with an error message.
Examples
Move the first tab in the current window to the last position in the current window:
Move all tabs served over HTTP or HTTPS from *.mozilla.org to the end of their window:
Move all tabs served over HTTP or HTTPS from *.mozilla.org to the window that hosts the first such tab, starting at position 0:
{{WebExtExamples}}
Browser compatibility
{{Compat}}
Note: This API is based on Chromium's
chrome.tabsAPI. This documentation is derived fromtabs.jsonin the Chromium code.getZoom