connect method

Port connect(
  1. String? extensionId,
  2. ConnectInfo? connectInfo
)

Attempts to connect listeners within an extension/app (such as the background page), or other extensions/apps. This is useful for content scripts connecting to their extension processes, inter-app/extension communication, and web messaging. Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via tabs.connect. extensionId The ID of the extension or app to connect to. If omitted, a connection will be attempted with your own extension. Required if sending messages from a web page for web messaging. returns Port through which messages can be sent and received. The port's $(ref:Port onDisconnect) event is fired if the extension/app does not exist.

Implementation

Port connect(
  String? extensionId,
  ConnectInfo? connectInfo,
) {
  return Port.fromJS($js.chrome.runtime.connect(
    extensionId,
    connectInfo?.toJS,
  ));
}