Chrome-Extension: iterate through all tabs?

后端 未结 4 1051
小蘑菇
小蘑菇 2021-02-03 22:23

How would I iterate through all tabs a user has open and then check if they have a particular HTML item with id = \'item\'?

4条回答
  •  别那么骄傲
    2021-02-03 22:42

    You can make it like this :

    chrome.tabs.getAllInWindow(null, function(tabs){
        for (var i = 0; i < tabs.length; i++) {
        chrome.tabs.sendRequest(tabs[i].id, { action: "xxx" });                         
        }
    });
    

    After that to look after your item, if you can make it like this :

    document.getElementById('item')
    

    Don't forget that you can't manipulate the HTML by using the "background page" So the first code snip is for the background page, and the second have to be on a content script ;)

提交回复
热议问题