-
Notifications
You must be signed in to change notification settings - Fork 22.7k
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
Changes from all commits
47d05b8
e14dcfb
a717a38
af5f98e
579d0e3
5c91eac
5796ebc
7301671
1d24f35
15513a5
da46206
81fa00c
6e0ea9f
0542e29
4ba4715
f6e8436
1a7bc19
c581e68
8959d01
65222de
200a705
ceef2b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: tabGroups.Color | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/Color | ||
page-type: webextension-api-type | ||
browser-compat: webextensions.api.tabGroups.Color | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
The color of a tab group. | ||
|
||
## Type | ||
|
||
Values of this type are a string and can take these values: | ||
|
||
- blue | ||
- cyan | ||
- grey | ||
- green | ||
- orange | ||
- pink | ||
- purple | ||
- red | ||
- yellow | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: tabGroups.get | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/get | ||
page-type: webextension-api-function | ||
browser-compat: webextensions.api.tabGroups.get | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
Returns details about a tab group. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
let tabGroupDetails = await browser.tabGroups.get( | ||
groupId // integer | ||
); | ||
``` | ||
|
||
### Parameters | ||
|
||
- `groupId` | ||
- : `integer`. The ID of the tab group to return details for. | ||
|
||
### Return value | ||
|
||
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) fulfilled with a {{WebExtAPIRef("tabGroups.TabGroup")}} object. If the request fails, the promise is rejected with an error message. | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: tabGroups | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups | ||
page-type: webextension-api | ||
browser-compat: webextensions.api.tabGroups | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
This API enables extensions to modify and rearrange [tab groups](https://support.mozilla.org/en-US/kb/tab-groups). | ||
|
||
Tab groups may persist across browser restarts as part of session restore. Tab groups in private browsing windows do not persist across restarts. When a tab group is restored, its `groupId` may differ from its original value. | ||
|
||
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 | ||
|
||
To use this API, an extension must request the `"tabGroups"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in its [`manifest.json`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file. The `"tabGroups"` permission is not shown to users in permission prompts. | ||
|
||
## Types | ||
|
||
- {{WebExtAPIRef("tabGroups.Color")}} | ||
- : The color of a tab group. | ||
- {{WebExtAPIRef("tabGroups.TabGroup")}} | ||
- : The state of a tab group. | ||
|
||
## Properties | ||
|
||
- {{WebExtAPIRef("tabGroups.TAB_GROUP_ID_NONE")}} | ||
- : The tab group ID value returned when a tab isn't in a tab group. | ||
|
||
## Functions | ||
|
||
- {{WebExtAPIRef("tabGroups.get()")}} | ||
- : Returns details about a tab group. | ||
- {{WebExtAPIRef("tabGroups.move()")}} | ||
- : Moves a tab group within or to another window. | ||
- {{WebExtAPIRef("tabGroups.query()")}} | ||
- : Returns all tab groups or finds tab groups with certain properties. | ||
- {{WebExtAPIRef("tabGroups.update()")}} | ||
- : Modifies the state of a tab group. | ||
|
||
## Events | ||
|
||
- {{WebExtAPIRef("tabGroups.onCreated")}} | ||
- : Fires when a tab group is created. | ||
- {{WebExtAPIRef("tabGroups.onMoved")}} | ||
- : Fires when a tab group is moved within a window or to another window. | ||
- {{WebExtAPIRef("tabGroups.onRemoved")}} | ||
- : Fires when a tab group is removed. | ||
- {{WebExtAPIRef("tabGroups.onUpdated")}} | ||
- : Fires when a tab group is updated. | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## See also | ||
|
||
- {{WebExtAPIRef("tabs.group()")}} | ||
- {{WebExtAPIRef("tabs.ungroup()")}} | ||
- {{WebExtAPIRef("tabs.query()")}} | ||
- {{WebExtAPIRef("tabs.Tab")}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: tabGroups.move | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/move | ||
page-type: webextension-api-function | ||
browser-compat: webextensions.api.tabGroups.move | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
Moves a tab group within or to another window. Groups can't be moved before a pinned tab or inside another tab group. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
let movedTabGroup = await browser.tabGroups.move( | ||
groupId, // integer | ||
moveProperties // object | ||
); | ||
``` | ||
|
||
### Parameters | ||
|
||
- `groupId` | ||
|
||
- : `integer` The ID of the tab group to move. | ||
|
||
- `moveProperties` | ||
- : An object containing details of the location to move the tab group to. | ||
- `index` | ||
- : `integer`. The position to move the group to. After moving, the first tab in the tab group is at this index in the tab strip. Use -1 to place the group at the end of the window. | ||
- `windowId` {{optional_inline}} | ||
- : `integer`. The window to move the group to. Defaults to the window the group is in. Groups can only be moved to and from windows with {{WebExtAPIRef("windows.WindowType")}} type `"normal"`. | ||
|
||
### Return value | ||
|
||
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) fulfilled with a {{WebExtAPIRef("tabGroups.TabGroup")}} object. If the request fails, the promise is rejected with an error message. | ||
|
||
{{WebExtExamples("h2")}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: tabGroups.onCreated | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/onCreated | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.tabGroups.onCreated | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
Fires when a tab group is created. | ||
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In Chrome, this event is also fired when a tab group is moved between windows, instead of {{WebExtAPIRef("tabGroups.onMoved")}}. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.tabGroups.onCreated.addListener(listener) | ||
browser.tabGroups.onCreated.removeListener(listener) | ||
browser.tabGroups.onCreated.hasListener(listener) | ||
``` | ||
|
||
Events have three functions: | ||
|
||
- `addListener(listener)` | ||
- : Adds a listener to this event. | ||
- `removeListener(listener)` | ||
- : Stops listening to this event. The `listener` argument is the listener to remove. | ||
- `hasListener(listener)` | ||
- : Checks whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. | ||
|
||
## addListener syntax | ||
|
||
### Parameters | ||
|
||
- `listener` | ||
|
||
- : The function called when this event occurs. The function is passed this argument: | ||
|
||
- `group` | ||
- : {{WebExtAPIRef("tabGroups.TabGroup")}}. Details of the created tab group's state. | ||
|
||
## Examples | ||
|
||
Listen for and log tab group creation: | ||
|
||
```js | ||
function tabGroupCreated(group) { | ||
console.log( | ||
`Tab group with ID ${group.id} was created in window ${group.windowId}.`, | ||
); | ||
} | ||
|
||
browser.tabGroups.onCreated.addListener(tabGroupCreated); | ||
``` | ||
|
||
{{WebExtExamples}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
title: tabGroups.onMoved | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/onMoved | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.tabGroups.onMoved | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
Fires when a tab group is moved within a window or to another window. {{WebExtAPIRef("tabs.onMoved")}} also fire for the tabs within the group. | ||
|
||
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The event is passed a {{WebExtAPIRef("tabGroups.TabGroup")}} object. This includes the `windowId` but not the position of the tab group. To determine the position of the tab group, use {{WebExtAPIRef("tabs.query()")}} with the `groupId`, and read the `index` property of the returned tab. | ||
|
||
In Chrome, this event doesn't fire when a tab group is moved between windows; instead, the group is removed from one window and created in another (firing {{WebExtAPIRef("tabGroups.onRemoved")}} and {{WebExtAPIRef("tabGroups.onCreated")}}. | ||
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dotproto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.tabGroups.onMoved.addListener(listener) | ||
browser.tabGroups.onMoved.removeListener(listener) | ||
browser.tabGroups.onMoved.hasListener(listener) | ||
``` | ||
|
||
Events have three functions: | ||
|
||
- `addListener(listener)` | ||
- : Adds a listener to this event. | ||
- `removeListener(listener)` | ||
- : Stops listening to this event. The `listener` argument is the listener to remove. | ||
- `hasListener(listener)` | ||
- : Checks whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. | ||
|
||
## addListener syntax | ||
|
||
### Parameters | ||
|
||
- `listener` | ||
|
||
- : The function called when this event occurs. The function is passed this argument: | ||
|
||
- `group` | ||
- : {{WebExtAPIRef("tabGroups.TabGroup")}}. Details of the moved tab group's state. | ||
|
||
## Examples | ||
|
||
Listen for and log tab group movement: | ||
|
||
```js | ||
function tabGroupMoved(group) { | ||
console.log( | ||
`Tab group with ID ${group.id} was moved to window ${group.windowId}.`, | ||
); | ||
} | ||
|
||
browser.tabGroups.onMoved.addListener(tabGroupMoved); | ||
``` | ||
dotproto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Locate a tab group moved to another window. | ||
|
||
```js | ||
browser.tabGroups.onMoved.addListener(group => { | ||
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 | ||
|
||
{{Compat}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: tabGroups.onRemoved | ||
slug: Mozilla/Add-ons/WebExtensions/API/tabGroups/onRemoved | ||
page-type: webextension-api-event | ||
browser-compat: webextensions.api.tabGroups.onRemoved | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
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. | ||
|
||
rebloor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.tabGroups.onRemoved.addListener(listener) | ||
browser.tabGroups.onRemoved.removeListener(listener) | ||
browser.tabGroups.onRemoved.hasListener(listener) | ||
``` | ||
|
||
Events have three functions: | ||
|
||
- `addListener(listener)` | ||
- : Adds a listener to this event. | ||
- `removeListener(listener)` | ||
- : Stops listening to this event. The `listener` argument is the listener to remove. | ||
- `hasListener(listener)` | ||
- : Checks whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. | ||
|
||
## addListener syntax | ||
|
||
### Parameters | ||
|
||
- `listener` | ||
|
||
- : The function called when this event occurs. The function is passed this argument: | ||
|
||
- `group` | ||
- : {{WebExtAPIRef("tabGroups.TabGroup")}}. Details of the removed tab group's state. | ||
- `removeInfo` | ||
- : `object`. Information on why the tab group is closing. | ||
- `isWindowClosing` | ||
- : `boolean`. `true` if the tab group is removed because its window is closing. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add This is part of the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1965007 Note: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Rob--W done, I assume there was no need to document this as an extra object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You wrote "done", but the change is not reflected in the PR yet. If by "not an extra object", you meant "not a separate article", then my answer is yes. The BCD does need a new PR for removeInfo, because Chrome does not support it. |
||
## Examples | ||
|
||
Listen for and log tab group removals: | ||
|
||
```js | ||
function tabGroupRemoved(group) { | ||
console.log(`Tab group with ID ${group.id} was removed.`); | ||
} | ||
|
||
browser.tabGroups.onRemoved.addListener(tabGroupRemoved); | ||
``` | ||
|
||
{{WebExtExamples}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
Uh oh!
There was an error while loading. Please reload this page.