There are 2 sendMessage
functions in Chrome API.
-
chrome.runtime.sendMessage
sends a message to all open extension pages (i.e. background, popup, etc.) -
chrome.tabs.sendMessage
sends a message to all content scripts from the extension in a given tab (possibly filtered by frame ID)
So, to send a message TO a content script, you need to use chrome.tabs
. To send a message FROM a content script (or within the extension pages), you need to use chrome.runtime
.
The event is chrome.runtime.onMessage
in both cases.
See Messaging docs for more details.