Closed Bug 1486050 Opened 6 years ago Closed 6 years ago

Impossible to change multiselection state of tabs by setting "highlighted" attribute of tabs without focus change


(WebExtensions :: General, enhancement, P5)



(firefox63 verified)

Tracking Status
firefox63 --- verified


(Reporter: yuki, Assigned: Oriol)


(Keywords: dev-doc-complete)


(2 files)

By the bug 1479129 now I can set multiselection state of tabs by setting "highlight" to true via browser.tabs.update(). However there is a side effect: it always activate the newly highlighted tab. Due to this restriction, any addon cannot simulate Firefox's tab multiselection behavior for Shift-click on its custom tabbar-like UI, ex: Tree Style Tab addon.

# Steps to reproduce

 1. Prepare multiple tabs. Assume that there are two tabs:
    * [tabA, id=1, active=true, highlighted=true]
    * [tabB, id=2]
 2. Execute browser.tabs.update(2, { highlighted: true, active: false });

# Actual result

The originally activated tab become inactive and the newly highlighted tab become active:

* [tabA, id=1, highlighted=true]
* [tabB, id=2, active=true, highlighted=true]

# Expected result

The originally activated tab stays active:

* [tabA, id=1, active=true, highlighted=true]
* [tabB, id=2, highlighted=true]

# Additional info

This behavior is quite same to Google Chrome, but I think the expected behavior is quite necessary. Even if it breaks compatibility with Chrome's API, I think it is reasonable that updating with "{ highlighted: true, active: false }" to set tab's highlighted state without any side effect, as an advantage behavior of Firefox's WebExtensions API.
There is a workaround:

const tabs = await browser.tabs.query({});
const activeTabId = tabs.filter(tab =>[0].id;
// 1. set non-active multiselected tabs highlighted. It changes focus of tabs.
for (const tab of tabs) {
  if (!
    browser.tabs.update(, { highlighted: true });
// 2. set old active tab to unhighlighted
// (because setting highlighted=true for already highlighted tab does nothing)
browser.tabs.update(activeTabId, { highlighted: false });
// 3. set old active tab to highlighted
browser.tabs.update(activeTabId , { highlighted: true });

but it produces annoying flicking of the content area.
I agree with the need to be able to set highlight without active, and we kind of touched on this during a recent review.  Can we support a non-chrome behavior if both highlighted and active are supplied to update?
Flags: needinfo?(oriol-bugzilla)
I agree that breaking with Chrome behavior in this case makes sense.
Severity: normal → enhancement
Priority: -- → P5
(In reply to YUKI "Piro" Hiroshi from comment #1)
> There is a workaround:
> but it produces annoying flicking of the content area.

I guess another workaround which avoids flickering would be

  async function highlightTabWithoutActivating(tabId) {
    let {index, windowId} = await browser.tabs.get(tabId);
    let indices = [index];
    let highlighted = await browser.tabs.query({windowId, highlighted: true});
    for (let {index, active} of highlighted)
      indices[active ? "unshift" : "push"](index);
    return browser.tabs.highlight({windowId, tabs: indices});

But I agree it's annoying that {highlighted: true, active: false} doesn't work with tabs.update.

Shouldn't be much difficult to implement.
Assignee: nobody → oriol-bugzilla
Flags: needinfo?(oriol-bugzilla)
Comment on attachment 9003939 [details]
Bug 1486050 - Don't change selected tab when browser.tabs.update is called with {highlighted: true, active: false}. r=mixedpuppy

Shane Caraveo (:mixedpuppy) has approved the revision.
Attachment #9003939 - Flags: review+
Pushed by
Don't change selected tab when browser.tabs.update is called with {highlighted: true, active: false}. r=mixedpuppy
Keywords: checkin-needed
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Verified as fixed using Firefox 63.0b(20180904170936) with Windows 10x64 and macOS 10.13.6.

I will attach a postfix video.
Attached image Postfix video
Created a pull request for browser compatibility status and added the following to 63 release notes ():

{{WebExtAPIRef("tabs.update")}} now supports changing the selection status of a tab without changing the focused tab ({{bug(1486050)}}).
Flags: needinfo?(oriol-bugzilla)
I have clarified the interaction of active and highlighted in
Flags: needinfo?(oriol-bugzilla)
You need to log in before you can comment on or make changes to this bug.