Skip to content

Instantly share code, notes, and snippets.

@EduardoAC
Created November 5, 2023 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoAC/789d05a169259c67aab722b571b7dae5 to your computer and use it in GitHub Desktop.
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.
// 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