Sends a single message to event listeners within your extension or a different extension.
If sending to your extension, omit the extensionId
argument. The runtime.onMessage
event will be fired in each page in your extension, except for the frame that called runtime.sendMessage
.
If sending to a different extension, include the extensionId
argument set to the other extension's ID. runtime.onMessageExternal
will be fired in the other extension.
Extensions cannot send messages to content scripts using this method. To send messages to content scripts, use tabs.sendMessage
.
This is an asynchronous function that returns a Promise
.
Note: You can also use a connection-based approach to exchange messages.