sendMessage method
Sends a single message to event listeners within your extension or a
different extension/app. Similar to runtime.connect but only sends a
single message, with an optional response. If sending to your extension,
the runtime.onMessage event will be fired in every frame of your
extension (except for the sender's frame), or runtime.onMessageExternal,
if a different extension. Note that extensions cannot send messages to
content scripts using this method. To send messages to content scripts,
use tabs.sendMessage.
extensionId The ID of the extension to send the message to. If
omitted, the message will be sent to your own extension/app. Required if
sending messages from a web page for web
messaging.
message The message to send. This message should be a JSON-ifiable
object.
returns Promise support was added for extension contexts in Chrome 99.
When communicating from a web page to an extension, promises are
available from Chrome 118.
Implementation
Future<Object?> sendMessage(
String? extensionId,
Object message,
SendMessageOptions? options,
) async {
var $res = await $js.chrome.runtime
.sendMessage(
extensionId,
message.jsify()!,
options?.toJS,
)
.toDart;
return $res?.dartify();
}