'active' tab VS. 'highlighted' tabs

6,565 views
Skip to first unread message

Raphaël Korach

unread,
Jul 26, 2013, 3:41:39 PM7/26/13
to chromium-...@chromium.org
Hi all,

I had trouble getting the difference between 'active' and 'highlighted' properties in Chrome extensions Tabs api
After a few tests, I just wanted to share my understanding of it, in case someone has the same issue.

So,
What is the difference between 'active' and 'highlighted' properties in Chrome extensions Tabs api?

- An active tab is always highlighted. There is only one active tab per window. Careful, as explained in the doc, a tab can be active even if it's not in the focused window.
- You can have several highlighted tabs in a same window. But then all highlighted tabs are not active. Example: select a tab, hold your Shift key, and select another tab. The last tab clicked will become the active tab for this window, but all tabs between them (including the two limit ones) are now highlighted.

My confusion was also coming from the fact that I thought that 'highlighted' was meaning 'hovered' (you can actually see a highlight on tabs when you hover them, plus it could be useful in the api for notifications, like when you get a mail or message in gmail/hangout).
I personally think that 'selected' would be a better wording.

Simple test for understanding, along with the previously described procedure:

chrome.tabs.query({
  'active':true,
}, function(lTabs) {
  console.log(lTabs)
});

and 

chrome.tabs.query({
  'highlighted':true,
}, function(lTabs) {
  console.log(lTabs)
});

Hope it can help someone one day. If any mistake from my part, please feel free to correct me!
Raphaël

Adrian Aichner

unread,
Jul 26, 2013, 4:54:43 PM7/26/13
to Raphaël Korach, Chromium-extensions
Interesting indeed!

How do you run the code snippet?

I run it from devtools opened by Inspect Element of a browser action popup.

This way the currentWindow property becomes important as well.

Here is the slightly upgraded version I am running from the devtools console:

chrome.tabs.query({ 'highlighted':true, 'currentWindow':true, 'active':undefined }, function(lTabs) { console.log(JSON.stringify(lTabs, null, 4)); console.log(lTabs.length); });

I was a bit surprised to find out these properties are actually tristates, which is handy.

See how I don't want to restrict the state active needs to be in, so I just set it to undefined.

The selection of tabs I still don't fully understand.

click, SHIFT+click, CTRL+click, and CTRL+SHIFT+click all have their uses.

See what you get for the query afterwards.

The best practical value I am deriving from CTRL+click right now.

Lets me quickly toggle back to the previously active tab instead of go hunting for it like until now.

The highlighting brightness change is way too subtle for me in the Chrome Classic theme to reliably recognize.

Thanks for the inspiration to explore this, Raphaël!

Adrian

Raphaël

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/bc8df907-65b1-4ca4-a9ea-49661bcf18a1%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.
 
 

Raphaël Korach

unread,
Jul 31, 2013, 10:32:50 PM7/31/13
to chromium-...@chromium.org, Raphaël Korach
For extension that we develop, we have a UI page that opens in a tab, so I would run the snippet directly form the devtool console of this page (it avoids the need of specifying the window if you did it from the background page, and - you're right - currentWindow is all you need)

I don't think the 'active' : undefined is necessary in your code though. If you don't specify it I think it should be the same behavior.
I just learnt about the tristate! Thanks a lot for the discovery!!

Just for fun after that, I also wanted to use the shift+click command functionality (multiple tabs selection) to do a quick extension that lets you move several tabs at the same time to create a new window, but the detach/attach event are not so easy to manage, plus you cannot manipulate tabs through the api as long as you are dragging one. Will try to find a hack on this when I find a little time :)

As for the 'highlight' (as in making the tab "blink"), it is not part of the api, but still think it could be fun. I know it's subtle but it's a nice way to have not so intrusive notifications.

I'm glad you got inspired to explore this topic Adrian, let us know about your future discoveries if any!

Raphaël.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
Reply all
Reply to author
Forward
0 new messages