Can I make any assumptions about the order of tabs returned by tabs.query
?
For instance, will the order of tabs in tabs.query({ currentWindow: true ])
be the same as the order in the current window’s tab strip?
Can I make any assumptions about the order of tabs returned by tabs.query
?
For instance, will the order of tabs in tabs.query({ currentWindow: true ])
be the same as the order in the current window’s tab strip?
You always can make assumptions, but I wouldn’t risk it here. Just do:
(await browser.tabs.query({ currentWindow: true, })).sort((a, b) => a.index - b.index)
The sorting should be pretty quick if the array was already sorted and if not, it was probably worth the effort.
Thanks, that’s a good suggestion. I wasn’t as worried about performance as I was curious about how the query
API behaved in this case. Explicitly sorting the result more clearly conveys my intent.