Skip to content

Addition of the webextensions.api.tabGroups documentation #39370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Further feedback changes
  • Loading branch information
rebloor committed May 8, 2025
commit f6e8436f3490cab74100164d361ab955abeb680a
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The color of a tab group.

## Type

Values of this type are a {{jsxref("string")}} and can take these values:
Values of this type are a string and can take these values:

- blue
- cyan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This API enables extensions to modify and rearrange [tab groups](https://support

Tab groups persist across browser restarts, except for tab groups in private browsing windows.

The `tabGroups` API does not offer the ability to create or remove tab groups. Use the {{WebExtAPIRef("tabs.group()")}} and {{WebExtAPIRef("tabs.ungroup()")}} methods instead. To query the position of a tab group within a window, use {{WebExtAPIRef("tabs.query()")}}. These APIs in the `tabs` namespace do not require any permissions.
The `tabGroups` API doesn't offer the ability to create or remove tab groups. Use the {{WebExtAPIRef("tabs.group()")}} and {{WebExtAPIRef("tabs.ungroup()")}} methods instead. To query the position of a tab group within a window, use {{WebExtAPIRef("tabs.query()")}}. These APIs in the `tabs` namespace don't require any permissions.

## Permissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ function tabGroupMoved(group) {
browser.tabGroups.onMoved.addListener(tabGroupMoved);
```

Locate a tab group moved to another window.

```js
let tabs = await browser.tabs.query({
groupId: group.id,
});
console.log(`Moved tab group to ${tabs[0].index} in window ${group.windowId}`);
```

{{WebExtExamples}}

## Browser compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ browser-compat: webextensions.api.tabGroups.onRemoved

{{AddonSidebar}}

Fires when a tab group is removed. This can occur when a user closes a tab group or a tab group is closed automatically because another change means it no longer contained any tabs.
Fires when a tab group is removed. This occurs when a user closes a tab group or a tab group is closed automatically because another change means it no longer contained any tabs.

> [!NOTE] In Firefox, this event does not fire when a window is closed ([bug 1965007](https://bugzil.la/1965007)). As an alternative, use {{WebExtAPIRef("windows.onRemoved")}} to detect closed windows, and retrieve the remaining set of groups with {{WebExtAPIRef("tabGroups.query()")}}.
> [!NOTE]
> In Firefox, this event doesn't fire when a window closes ([bug 1965007](https://bugzil.la/1965007)). As an alternative, use {{WebExtAPIRef("windows.onRemoved")}} to detect closed windows, and retrieve the remaining set of groups with {{WebExtAPIRef("tabGroups.query()")}}.

## Syntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ The tab group ID value returned when a tab isn't in a tab group.

Its value is `-1`.

This value can appear as `groupId` in the following APIs:
This value can appear as `groupId` in these API functions:

- {{WebExtAPIRef("tabs.group()")}}
- {{WebExtAPIRef("tabs.ungroup()")}}
- {{WebExtAPIRef("tabs.query()")}}
- {{WebExtAPIRef("tabs.Tab")}}

The `tabGroups.TAB_GROUP_ID_NONE` constant is part of the `tabGroups` namespace, which is only available when the [`tabGroups` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabGroups#permissions) has been granted. If your extension does not require the `tabGroups` permission, use `-1` instead of `tabGroups.TAB_GROUP_ID_NONE`.
The `tabGroups.TAB_GROUP_ID_NONE` constant is part of the `tabGroups` namespace, which is only available when the [`tabGroups` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabGroups#permissions) is granted. If your extension doesn't require the `tabGroups` permission, use `-1` instead of `tabGroups.TAB_GROUP_ID_NONE`.

{{WebExtExamples("h2")}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ The state of a tab group.

## Type

Values of this type are objects that can contain these properties:
Values of this type are strings. Possible values are:

- `collapsed`
- : `boolean`. Whether the tab group is collapsed or expanded in the tab strip.
- `color`
- : A {{WebExtAPIRef("tabGroups.Color")}} type for the name of the user-selected color for the tab group's label and icons.
- : {{WebExtAPIRef("tabGroups.Color")}}. The name of the user-selected color for the tab group's label and icons.
- `id`
- : An `integer` representing the unique ID of the tab group. Contains the {{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}} value when the tab isn't in a tab group.
- : `integer` The unique ID of the tab group. Contains the {{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}} value when the tab isn't in a tab group.
- `title`
- : A {{jsxref("string")}} containing the user-defined name of the tab group.
- : `string`. The user-defined name of the tab group.
- `windowId`
- : An `integer` representing the unique ID of the window the tab group is in.
- : `integer`. The unique ID of the window the tab group is in.

{{WebExtExamples("h2")}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ If a call moves tabs out of tab groups and any of those tab groups become empty,
> [!NOTE]
> The `tabs.group()` method is not the only way to group tabs. A tab also joins a tab group when {{WebExtAPIRef("tabs.move")}} places it between tabs that are part of a tab group.

For more information on tab groups, see {{WebExtAPIRef("tabGroups")}}.

## Syntax

```js-nolint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ browser-compat: webextensions.api.tabs.query

Gets all tabs that have the specified properties, or all tabs if no properties are specified.

This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

## Syntax

```js-nolint
Expand Down Expand Up @@ -40,7 +38,7 @@ let querying = browser.tabs.query(queryInfo)
- `discarded` {{optional_inline}}
- : `boolean`. Whether the tabs are discarded. A discarded tab is one whose content has been unloaded from memory, but is still visible in the tab strip. Its content gets reloaded the next time it's activated.
- `groupId` {{optional_inline}}
- : `integer`. The ID of the tab group the tabs are in or {{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}} for ungrouped tabs.
- : `integer`. The ID of the tab group the tabs are in or `-1` ({{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}}) for ungrouped tabs. For more information on tab groups, see {{WebExtAPIRef("tabGroups")}}.
- `hidden` {{optional_inline}}
- : `boolean`. Whether the tabs are hidden.
- `highlighted` {{optional_inline}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Values of this type are objects. They contain the following properties:
- `favIconUrl` {{optional_inline}}
- : `string`. The URL of the tab's favicon. Only present if the extension has the `"tabs"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) or [host permissions](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions). It may also be `undefined` if the page has no favicon, or an empty string if the tab is loading.
- `groupId` {{optional_inline}}
- : `integer`. The ID of the tab group the tab belongs to. Set to {{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}} if the tab doesn't belong to a tab group. See {{WebExtAPIRef("tabs.group")}}.
- : `integer`. The ID of the tab group the tab belongs to. Set to `-1` ({{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}}) if the tab doesn't belong to a tab group. See {{WebExtAPIRef("tabs.group")}}. For more information on tab groups, see {{WebExtAPIRef("tabGroups")}}.
- `height` {{optional_inline}}
- : `integer`. The height of the tab in pixels.
- `hidden`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ All tabs in a tab group must be adjacent. If necessary, an ungrouped tab is move
> [!NOTE]
> The `tabs.ungroup()` method is not the only way to ungroup tabs. A tab is also ungrouped when it's moved by calling {{WebExtAPIRef("tabs.move")}} with an `index` that is outside a tab group.

For more information on tab groups, see {{WebExtAPIRef("tabGroups")}}.

## Syntax

```js-nolint
Expand Down