Sometimes backgroud.js needs to synchronize messages to all tabs at the same time. At this time, it is necessary to obtain the tabid of all tabs . The following method can be implemented.
function open_all_tab(){
// 获取所有的页签
chrome.tabs.getAllInWindow(null, function(tabs){
for (var i = 0; i < tabs.length; i++) {
// 在控制台打印出页签的tabid
console.log(tabs[i].id);
// 通过tabid向每一个页签发送消息
chrome.tabs.sendMessage(tabs[i].id, {
type: 'xxx'});
}
});
}
Like it if you like it ❤!