-
Notifications
You must be signed in to change notification settings - Fork 5
Communication channels
Simon Warta edited this page Apr 30, 2019
·
4 revisions
- Message format: JSON
(see https://stackoverflow.com/questions/8593896/chrome-extension-how-to-pass-arraybuffer-or-blob-from-content-script-to-the-bac; also verified manually)
- Receiver (background script): Setup listener via
chrome.runtime.onMessageExternal.addListener()
- Sender (website): Call
chrome.runtime.sendMessage()
with the extension ID as the first argument - Limitations: websites must be whitelisted in manifest.json's externally_connectable where at least a second level domain must be specified.
- Receiver (extension): Setup listener via
chrome.runtime.onMessage.addListener()
- Sender (backround script): Call
chrome.runtime.sendMessage()
Step 1:
- Receiver (content script): Setup listener via
window.addEventListener()
(addEventListener) - Sender (website): Call
window.dispatchEvent()
(dispatchEvent) - Format: structured clone algorithm
- Note: Don't use the messaging system via Window.postMessage() and type "message" events to avoid any kind of cross-origin communication.
Step 2:
- Receiver (extension): Setup listener via
chrome.runtime.onMessage.addListener()
- Sender (backround script): Call
chrome.runtime.sendMessage()
This solution requires explicit matching of request/response by ID since events don't have a back channel. IOV-Core's JsonRpcClient
could be used to simplify that.