Created
November 5, 2023 10:12
-
-
Save EduardoAC/789d05a169259c67aab722b571b7dae5 to your computer and use it in GitHub Desktop.
Chrome Extension: Broadcasting a message to all tabs currently loaded in the browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Message and response are define in https://gist.github.com/EduardoAC/000b1e39a6ec10a892e7c6cd93730a53 | |
export function broadcastMessageAllLoadedTabs<T>(message: Message<T>) { | |
// Get all tabs not discarded - it can be optimise further | |
chrome.tabs.query({ discarded: false }, (tabs) => { | |
tabs.forEach(({ id, status }) => { | |
if(status !== "unloaded") { | |
sendMessage(id, message) | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment