Closed Bug 1959714 Opened 1 year ago Closed 1 year ago

Implement tabs.group() and tabs.ungroup()

Categories

(WebExtensions :: General, enhancement, P1)

enhancement

Tracking

(firefox138 fixed, firefox139 fixed)

RESOLVED FIXED
139 Branch
Tracking Status
firefox138 --- fixed
firefox139 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(2 external files)

Even without knowing the name, color, etc. of a tab groups, it is already useful/feasible to add or remove tabs from existing groups.
For example, the Multi Account Container extension moves tabs with specific URLs to a different container by creating a new tab and removing the old one (because it is not possible to change the container of an existing tab). While doing so, it would be ideal if the original tab group can be preserved, which is currently not possible.

Semantics:

  • tabs.group(): When the specified tab(s) are not already adjacent to a tab group, they are moved to the closest index before or after a tab group (index changes).
  • tabs.ungroup(): When the specified tab(s) are not at the boundaries of a tab group, they are moved after the tab group.
  • If a tab is already pinned, it becomes unpinned before grouping.
  • tabs.group() can create new tab group when groupId is not specified. Defaults to within the current window, but can be customized via options.createProperties.windowId.
  • tabs.group() validation:
    • If groupId is specified and invalid, an error is raised.
    • If windowId is specified and invalid, an error is raised.
    • If neither groupId nor windowId are specified, the current window is used, but may throw an error if there is no browser window.
    • If any of the tabIds are invalid, an error is raised.

When tabs.group() / tabs.ungroup() is implemented, an extension that wants to create a new tab based on a previous tab can do something like this:

let [ oldTab ] = await browser.tabs.query({ index: 0 });

let newTab = await browser.tabs.create({
  url: oldTab.url,
  index: oldTab.index,
  // cookieStoreId: ..., etc.
});
if (browser.tabs.group) {
  if (oldTab.groupId !== -1) {
    await browser.tabs.group({ groupId: oldTab.groupId, tabIds: [newTab.id] });
  } else {
    await browser.tabs.ungroup(newTab.id);
  }
}

await browser.tabs.remove(oldTab.id);
Blocks: 1949139
No longer blocks: 1949139
Duplicate of this bug: 1949139
Blocks: 1956278
See Also: → 1939214
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/76583f7a0558 Implement tabs.group() and tabs.ungroup() r=zombie,dao,frontend-codestyle-reviewers
Regressions: 1960126
Blocks: 1947853
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 139 Branch
No longer regressions: 1960126
Attachment #9478856 - Flags: approval-mozilla-beta?

beta Uplift Approval Request

  • User impact if declined: Extensions unable to distinguish tabs in tab groups, which may result in the loss of tab groups (e.g. by the MAC extension), see https://bugzilla.mozilla.org/show_bug.cgi?id=1956278#c22
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: Not needed; covered by automated tests.
  • Risk associated with taking this patch: Low
  • Explanation of risk level: Patch stack has low risk changes to extension APIs, see D245395; This patch specifically (D245397) introduces new methods that are covered by automated tests.
  • String changes made/needed: None
  • Is Android affected?: no
Attachment #9478856 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: