My extension needs to do something with the currently active tab. So I use
browser.tabs.query({active: true, currentWindow: true}).then((tabs) =>
  let tab = tabs[0];
  if (tab) {
    // actual code
  } else {
    log("no active tab")
  }
);
Mostly out of curiosity: are there cases where tabs will have more than one tab?
TLDR: No
For Chrome, Opera and Firefox this is currently impossible, so it's safe to assume that the array will only contain one element.
Opera has multi-select of tabs, but it uses the property highlighted to indicate the multi-select status. active means "visibly selected in window": the contents of the tab are visible in the browser window.
browser.tabs.query returns an array, regardless of the filter you pass to it. It also returns an array when filtering on "index", containing one result if you have one window open.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With