I was messing around with communicating inside a Google Chrome extension and was using the following guide: https://developer.chrome.com/extensions/messaging
It used
tabs
is the list of all tabs (regardless of position) that pass the filter.
Your query is {active: true, currentWindow: true}
, so normally it should be just 1 tab (as there is at most 1 current window with exactly 1 active tab).
So you need the first element, which is tabs[0]
.
tabs[1]
will always be undefined with this query.
Cases when tabs
will be empty empty used to be exceedingly rare (Chrome running in background with no windows open).
However, with a recent change the API will not return the Dev Tools tab. So if you're debugging your extension and the Dev Tools window is open and focused, the array will be empty. You should check for that.