2

I have developed a Chrome extension, it works fine in Chrome 39 but gives an error in Opera developer 24 on Ubuntu 14.04 (64 bit).

Error in response to tabs.query: TypeError: Cannot read property 'id' of undefined at HTMLLIElement.click

So I tested chrome.tabs.query on both browser consoles:

chrome.tabs.query(
  { active: true, highlighted: true, currentWindow: true }, 
  function(thisTab) {
    console.log(thisTab);
  }
);

In Chrome it returns a complete Tab object.

But in Opera it returns a blank array [].

screenshots

Why this is happening?

Xan
  • 74,770
  • 16
  • 179
  • 206
xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • also anyone can tell me "which action causes to display `undefined` in console just before the result of `console.log` in both browser?" – xkeshav Dec 04 '14 at 06:10
  • 1
    the first `undefined` is the return value of `chrome.tabs.query` – Xan Dec 04 '14 at 08:01

1 Answers1

3

It seems that Opera does not include the concept of a highlighted tab, which is already pretty obscure in Chrome.

Your query is excessive anyway: in Chrome, the active tab cannot be non-highlighted.

So, for a query that works in both, use {active: true, currentWindow: true}.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Thank you once again for helping. console must gives proper error details instead of unidentified error. Isn't it? – xkeshav Dec 04 '14 at 09:04
  • 1
    No. It's just that there are no tabs with `highlighted: true`, so your filter returns an empty result. I guess the property itself is valid for backwards compatibility, so no explicit error. – Xan Dec 04 '14 at 09:06
  • I'm finding that **chrome.tabs.query({active: true, currentWindow: true}** is always returning 0 length array in chrome, any ideas? – SuperUberDuper Jul 06 '17 at 11:04
  • @SuperUberDuper I'm guessing https://stackoverflow.com/a/29683574/934239 – Xan Jul 06 '17 at 12:32