Chrome-Extension: iterate through all tabs?

后端 未结 4 1048
小蘑菇
小蘑菇 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 22:33

    This is a not deprecated vanilla way (may 2019):

    chrome.tabs.query({}, function(tabs){
            tabs.forEach(tb => {
                chrome.tabs.sendMessage(tb.id, { action: "xxx" });
            });
        });
    

提交回复
热议问题