Background script messaging with javascript

前端 未结 1 1345
有刺的猬
有刺的猬 2021-01-20 07:57

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

相关标签:
1条回答
  • 2021-01-20 08:17

    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.

    0 讨论(0)
提交回复
热议问题