Background script messaging with javascript

时光怂恿深爱的人放手 提交于 2019-12-01 22:18:38

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!