消息通信优化

This commit is contained in:
IndieKKY
2024-10-04 13:15:27 +08:00
parent 125996408e
commit c3b53a016c
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
export const broadcastMessage = async (ignoreTabIds: number[] | undefined | null, target: string, method: string, params?: any) => {
const tabs = await chrome.tabs.query({
discarded: false,
})
for (const tab of tabs) {
try {
if (tab.id && ((ignoreTabIds == null) || !ignoreTabIds.includes(tab.id))) {
await chrome.tabs.sendMessage(tab.id, {target, method, params})
}
} catch (e) {
console.error('send message to tab error', tab.id, e)
}
}
}