tabs.moveInSuccession()
Modifies the succession relationship for a group of tabs.
Using the tabs
API, a tab can be assigned a successor tab in the same window. If tab B is the successor of tab A, and tab A is closed while it is the active tab, tab B will be activated next. If tab A doesn't have a successor, then the browser is free to determine which tab to activate next. If tab B is the successor of tab A, then tab A is called a predecessor of tab B. A tab can have at most one successor, but it can have any number of predecessors. A tab cannot take itself or a tab in a different window as a successor.
All tabs start out with no successor; tabs only get a successor if assigned one by a WebExtension. However, the browser must not orphan a tab in a succession relationship with other tabs, if possible: if tab B is the successor of tab A, and tab C is the successor of tab B, and B is closed (or moved to another window), then tab A will take tab C as its successor. Preventing C from being orphaned in this way is called moving a tab (B) from its line of succession.
tabs.moveInSuccession()
takes an array of tab IDs, and moves all of those tabs from their lines of succession. It then makes each tab the successor of the previous tab in the array, forming a chain. It can optionally set the successor of the last tab in the chain to an anchor tab, which is not moved from its line of succession. Additional options can control whether the tab chain is "prepended" or "appended" to the anchor tab, and whether the operation acts like a linked-list insert.
While the successor tab can be assigned with tabs.update()
, it is often desirable to use tabs.moveInSuccession()
to change successors, even if only a single tab is having its successor assigned. The difference is that browser.tabs.moveInSuccession([a], b)
moves tab a
from its line of succession, so any predecessors of a
will adopt a
's previous successor; whereas if browser.tabs.update(a, {successorTabId: b})
is used instead, tab a
may continue to be the successor of other tabs, which could be unexpected. Another advantage of tabs.moveInSuccession()
is that all of the succession changes happen atomically, without having to worry about races between calls to tabs.update()
and tabs.get()
and other operations like the user closing a tab.
Syntax
browser.tabs.moveInSuccession([1, 3, 5, 7, 2, 9], 4, {insert:true})
Parameters
tabIds
-
array
ofinteger
. An array of tabID
s. The order of the elements in the array defines the relationship of the tabs. Any invalid tabID
s, or tabID
s corresponding to tabs not in the same window astabId
(or the first tab in the array, iftabId
is omitted), will be ignored—they will keep their current successors and predecessors. -
tabId
Optional -
integer.
TheID
of the tab that will be the successor of the last tab in thetabIds
array. If thisID
is invalid ortabs.TAB_ID_NONE
, the last tab will not have a successor. Defaults totabs.TAB_ID_NONE
. -
options
Optional -
object
. -
-
append
Optional -
boolean
. Determines whether to move the tabs intabIds
before or aftertabId
in the succession. Iffalse
, the tabs are moved beforetabId
, iftrue
, the tabs are moved aftertabId
. Defaults tofalse
. -
insert
Optional -
boolean
. Determines whether to link up the current predecessors or successor (depending onoptions.append
) oftabId
to the other side of the chain after it is prepended or appended. If true, one of the following happens: ifoptions.append
isfalse
, the first tab in the array is set as the successor of any current predecessors oftabId
; ifoptions.append
istrue
, the current successor of tabId is set as the successor of the last tab in the array. Defaults tofalse
.
-
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
moveInSuccession |
No |
No |
65 |
? |
No |
No |
? |
? |
No |
? |
? |
? |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/moveInSuccession